forked from nighk/brilliant-banking-server-challenge
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
executable file
·58 lines (46 loc) · 1.51 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
53
54
55
56
57
58
/**
* Initial entrypoint for the application
*/
import express from "express";
import passport from "passport";
import cookieSession from "cookie-session";
import ip from "ip";
import helmet from "helmet";
import cors from "cors";
import cookieParser from "cookie-parser";
import http from "http";
import mainRoutes from "./routes/mainRoutes.js";
import configurePassport from "./passport/configurePassport.js";
const app = express();
// Set the name of the application process, used in the stop script in the package.json
process.title = "brilliant-banking-server";
// Secures http headers to prevent potential security issues
app.use(helmet());
// Needed to get information from html forms
app.use(express.json());
// Enable the use of cookies for persistent login sessions
app.use(cookieSession(
{
name: "session",
key: "brilliant-banking-login-cookie",
secret: "M0xcUjFwFMU4KsWqWk9jpS48fgkzLo7Q",
secure: false,
httpOnly: false,
maxAge: 1000 * 60 * 60 * 24 * 30 // 1 month
}));
app.use(cookieParser())
// Enable CORS
app.use(cors({
origin: "http://localhost:3000",
credentials: true
}));
// Configure passport with defined strategies from ./config/passport
configurePassport(passport);
app.use(passport.initialize());
app.use(passport.session());
// Load custom routes
mainRoutes(app, passport);
const host = ip.address();
const port = 8080;
http.createServer(app).listen(port);
console.log("Server started at http://%s:%s", host, port);