-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
57 lines (46 loc) · 1.6 KB
/
index.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
53
54
55
56
57
const featuresRoutes = require("./routes/features.router.js");
const loginRoutes = require("./routes/login.router.js");
const cors = require('cors')
const mongoose = require("mongoose")
require('dotenv').config()
const http = require('http');
const express = require("express")
const app = express()
const bodyParser = require('body-parser')
const path = require('path')
const passport = require('passport');
const expressSession = require('express-session')({
secret: 'secret',
resave: false,
saveUninitialized: false
});
const rootDir = require('./util/path');
(async () => {
app.use(passport.initialize());
app.use(passport.session());
app.use(cors())
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(rootDir, 'public')))
app.set('view engine', 'pug')
app.set('views', 'views')
app.use(bodyParser.json());
app.use(expressSession);
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
})
//connect to mongodb
mongoose
.connect(process.env.database)
.then(() => console.log("Connected to MongoDB..."))
.catch(err => console.error("Could not connect to MongoDB..."));
app.use(express.json());
//use users route for api/users
app.use("/", featuresRoutes);
app.use("/", loginRoutes);
const port = process.env.PORT || 3000;
const server = await http.createServer(app).listen(port);
server.timeout = 300000;
})();