-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (32 loc) · 1.24 KB
/
index.js
File metadata and controls
37 lines (32 loc) · 1.24 KB
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
const path = require('path');
const express = require('express');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const device = require('express-device');
const { PORT, SECRET_KEY } = require('./config/constants');
const { initRoutes } = require('./routes/routes');
const db = require('./database/db');
const app = express();
app.use((req, res, next) => {
//res.setHeader('Access-Control-Allow-Origin', '*'); //Don't think we need CORS here.
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content, Accept, Content-Type, Authorization'
);
res.setHeader(
'Access-Control-Allow-Methods',
'GET, POST, PUT, DELETE, PATCH, OPTIONS'
);
next();
});
app.set('views', path.join(__dirname, 'views')) // Redirect to the views directory inside the src directory
app.use(express.static(path.join(__dirname, '../public'))); // load local css and js files
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser()); //Parse the cookie data (User ID).
app.use(device.capture());
initRoutes(app);
const port = PORT || 3000;
app.listen(port, () => console.log(`Server listening on port ${port}`));
export default app;