-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 1.5 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
58
59
60
61
62
63
//initialize the variables
const express = require("express");
const port = process.env.PORT || 8000;
const passport = require("passport");
const passportJwt = require("./config/passport-jwt-strategy");
const session = require("express-session");
const passportGoogle = require("./config/passport-google-oauth2-strategy");
const env = require("./config/environment");
const bodyParser = require("body-parser");
const app = express();
//fix CORS
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Methods",
"GET,HEAD,OPTIONS,POST,PUT,PATCH,DELETE"
);
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Auth-Token"
);
next();
});
//set up middlewares
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.json());
//set up database
const db = require("./config/mongoose");
//set up passport
app.use(
session({
name: "kelvinElectric",
secret: env.session_secret,
saveUninitialized: false,
resave: false,
cookie: {
maxAge: 1000 * 60 * 100,
},
})
);
app.use(passport.initialize());
app.use(passport.session());
//set up views
app.set("view engine", "ejs");
app.set("views", "./views");
//set up routes
app.use("/", require("./routes"));
//start the server
app.listen(port, function (err) {
if (err) {
console.log(`Error in starting the server: ${err}`);
return;
}
console.log(`The server is fired at port: ${port}`);
});