-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
52 lines (40 loc) · 1.37 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
51
52
const { urlencoded } = require("express");
const express = require("express");
const path = require("path");
const cookieParse = require("cookie-parser");
const bodyParser = require('body-parser')
const session = require('express-session')
const mongodbStore = require('connect-mongodb-session')(session)
const cors = require('cors')
const multer = require('multer')
require("dotenv").config();
require("./db/conn");
const views_path = path.join(__dirname, "/views");
const static_path = path.join(__dirname, "/static");
const Auth = require('./routes/auth.route')
const app = express();
const port = process.env.PORT || 80;
const store = new mongodbStore({
uri: process.env.MONGO_URI,
collection: 'sessions'
})
app.use(cors({
origin: '*',
credentials: true
}))
app.use(session({ secret: process.env.SECRET_KEY, resave: false, saveUninitialized: false, store: store, cookie: {maxAge: 12 * 60 * 60 * 1000}}))
app.use("/static", express.static(static_path));
app.use(express.json());
app.use(urlencoded({ extended: true }));
app.use(cookieParse());
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.set("view engine", "ejs");
app.set("views", views_path);
app.use(Auth)
app.listen(port, () => {
console.log(`The application started successfully on port ${port}`);
});
app.get('/', (req, res) => {
res.send({"server_status": "ok"})
})