-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (38 loc) · 1.43 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
// Get the dependencies
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'dist')));
app.use(cookieParser());
app.use(session({
secret: 'ablk',
resave: true,
saveUninitialized: true
})); //process.env.SESSION_SECRET
//Passport set up after cookie and session
app.use(passport.initialize());
app.use(passport.session());
// CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); // change to http://localhost:4200
res.header("Access-Control-Allow-Headers", "Origin, x-requested-with, Content-Type, Accept, authorization, client-security-token, Accept-Encoding");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Credentials", "true");
next();
});
const port = process.env.PORT || '3100';
app.set('port', port);
const server = http.createServer(app);
require("./server/app")(app);
server.listen( port );
// For Build: Catch all other routes and return the index file -- BUILDING
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});