-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
39 lines (31 loc) · 966 Bytes
/
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
// importing dependencies
const express = require('express');
const path = require('path');
// defining the port for heroku or local
const PORT = process.env.PORT || 3001;
// initializing app
const app = express();
// settting up express details
const expressSession = require('express-session')({
secret: 'secret',
resave: false,
saveUninitialized: false
});
// serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
} else {
require('dotenv').config();
}
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(expressSession);
// define any API routes before this runs
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
// initializing server
const server = require('http').createServer(app);
server.listen(PORT, () => {
console.log(`🌎 ==> API Socket server now on port ${PORT}!`);
});