-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (34 loc) · 1.2 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
const express = require('express');
const http = require("http");
const helmet = require('helmet');
const path = require("path");
const chalk = require("chalk");
var cors = require('cors');
const socketio = require("socket.io");
const bodyParser = require('body-parser');
const app = express();
const server = http.createServer(app);
const io = socketio(server);
console.log(chalk.bold.green(`Starting Express Server`));
const port = process.env.PORT || 5050;
//add securty to our application
app.use(helmet())
app.use(express.json())
app.use(cors())
if(process.env.NODE_ENV !== 'production') {
const morgan = require('morgan');
//superficial logging
app.use(morgan("tiny"));
}
//render react application
app.use(express.static(path.join(__dirname, "/Client/build/")));
require('./src/routes/api/route.js')(app);
require('./src/routes/socket/socket.js')(io);
//wildcard request; if request doesn't fit any predefined ones go to landing page
app.get('*', (request, response) =>{
response.sendFile(path.join(__dirname, "/Client/build/index.html"));
});
//server listening for any reqests on port
server.listen(port, () =>
console.log(chalk.bold.white(`Server listening on port `) + chalk.bold.magenta(port))
);