-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (46 loc) · 1.73 KB
/
server.js
File metadata and controls
61 lines (46 loc) · 1.73 KB
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
// Get the dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const app = express();
// loading authentication modules
const passport = require('passport');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const secret = process.env.SECRET || "this is the secret";
app.use(session({
secret: secret,
resave: true,
saveUninitialized: true
}));
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Point static path to dist -- For building -- REMOVE
app.use(express.static(path.join(__dirname, 'dist')));
// app.use(express.static(path.join(__dirname, 'src/assets')));
var cors = require('cors');
app.use(cors({credentials: true, origin: 'http://localhost:4200'}));
//CORS
app.use(function(reg, res, next){
res.header("Access-Control-Allow-Origin", "http://localhost:4200");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE, OPTIONS');
res.header("Access-Control-Allow-Credentials", "true");
next();
});
const port = process.env.PORT || '3100';
app.set('port', port);
// Create HTTP server
const server = http.createServer(app);
require('./server/app.js')(app);
// 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'));
});
server.listen( port , function() {
console.log('Node app is running on port', app.get('port'))});