-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (28 loc) · 1.1 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
"use strict";
/* Server environment setup */
// To run in development mode, run normally: node server.js
// To run in development with the test user logged in the backend, run: TEST_USER_ON=true node server.js
// To run in production mode, run in terminal: NODE_ENV=production node server.js
const env = process.env.NODE_ENV; // read the environment variable (will be 'production' in production mode)
const log = console.log;
const path = require("path");
const express = require("express");
// starting the express server
const app = express();
// enable CORS if in development, for React local development server to connect to the web server.
const cors = require("cors");
if (env !== "production") {
app.use(cors());
}
// Serve the build
app.use(express.static(path.join(__dirname, "/client/build")));
// All routes other than above will go to index.html
app.get("*", (req, res) => {
// send index.html
res.sendFile(path.join(__dirname, "/client/build/index.html"));
});
// Express server listening...
const port = process.env.PORT || 5000;
app.listen(port, () => {
log(`Listening on port ${port}...`);
});