-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (27 loc) · 877 Bytes
/
server.js
File metadata and controls
34 lines (27 loc) · 877 Bytes
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
const express = require('express');
require('dotenv').config()
const app = express();
const path = require('path')
const routes = require('./routes');
const PORT = process.env.PORT || 5000;
// connect to db
require('./models');
// configure body parser for AJAX requests
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(routes)
if (process.env.NODE_ENV === "production") {
// Set Static folder
app.use(express.static(path.resolve(__dirname, "client", "build")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
// const root = require("path").join(__dirname, "./build");
// app.use(express.static(root));
// app.get("*", (req, res) => {
// res.sendFile("index.html", { root });
// });
}
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}.`);
});