-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (48 loc) · 1.51 KB
/
app.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
const bodyParser = require("body-parser");
const express = require('express');
const logger = require('morgan');
const app = express();
const PORT = process.env.PORT || 3001;
const cors = require("cors");
const routes = require('./routes');
const passport = require('passport');
const helmet = require('helmet');
//socket io
// const http = require("http").createServer(app);
// const io = require('socket.io');
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(helmet());
// Set up cors
app.use(
cors({
origin: '*',
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With", "Content-Type", "Accept"],
preflightContinue: false,
credentials: true,
optionSuccessStatus: 200
})
)
// app.use(function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
// next();
// });
//socket io server side
// io.on('connection', client => {
// client.on('event', data => {});
// client.on('disconnect', ()=>{})
// })
//initializes the passport configuration
app.use(passport.initialize());
require("./config/passport_jwt")(passport);
//registers our authentication routes with Express.
app.use(routes);
//Serve static assets if we are in production
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.listen(PORT, () => {
console.log(`Listening on port http://localhost:${PORT}`);
})