-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (28 loc) · 1.09 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
// Import express package
const express = require('express');
// Import connectDB function to connect to mongoDB instance
const connectDB = require('./config/db')
// Initialize new instance of express
const app = express()
// create variable set to value of port server will be listening on
const port = process.env.PORT || 4000;
//import path package for file paths to static folders
const path = require('path');
// invoke function to connect to mongoDb instance
connectDB();
// Initialize express middleware to parse request body data within routes
app.use(express.json({ extend: false }));
// Routers
app.use('/logs', require('./src/server/routes/logs'));
app.use('/techs', require('./src/server/routes/techs'));
// Check the environment mode
if(process.env.NODE_ENV === 'production'){
// Set static folder to serve
app.use(express.static('build'));
// route to serve build folder
app.get('*', (req, res) => res.sendFile(path.resolve(__dirname,'build','index.html')));
}
// Set connection message to show when server started
app.listen(port, () => {
console.log(`Server listening on PORT: ${port}`)
});