forked from FRRe-DS/2021-TPI-G8
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
50 lines (35 loc) · 1.38 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require('express'); //Traigo la libreria de express
var session = require('express-session');
const bodyParser = require('body-parser'); //Luego de instalarlo, lo definimos
const cors = require("cors");
const path = __dirname + '/app/views/';
const app = express(); //Inicializo express en una variable
const router = express.Router(); //El router nos permite separar nuestras peticiones
app.use(express.static(path));
var corsOptions ={
origin: "localhost:8000"
}
//Es para informar a express que vamos a usar estos paquetes
app.use(cors(corsOptions));
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
//Le digo que usar a la variable app
app.use(express.json()); //Recibe json
app.use(express.urlencoded({extended:true})); //Recibe "Form URL encoded"
app.use(router); //Sirve para usar los diferentes métodos (GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD)
const db = require("./app/models");
const { sequelize, Sequelize } = require('./app/models');
db.sequelize.sync();
app.get('/', function (req,res) {
res.sendFile(path + "index.html");
});
require("./app/routes/routes.js")(app);
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});