-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
42 lines (33 loc) · 1.05 KB
/
app.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
const express = require('express');
const session = require('express-session');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const index = require('./controllers/index');
const user = require('./controllers/user');
const { sequelize } = require('./models');
//Initialize our app variable
const app = express();
sequelize.sync();
//Declaring Port
const port = 8001;
app.use(session({
secret: 'test1234',
resave: true,
saveUninitialized: true
}));
//Middleware for CORS
app.use(cors());
//Middleware for bodyparsing using both json and urlencoding
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
/*express.static is a built in middleware function to serve static files.
We are telling express server public folder is the place to look for the static files
*/
app.use(express.static(path.join(__dirname, 'public')));
app.use('/',index);
app.use('/user',user);
//Listen to port 3000
app.listen(port, () => {
console.log(`Starting the server at port ${port}`);
});