-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (27 loc) · 1008 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
const express = require('express');
const path = require('path');
const cors = require('cors');
const app = express();
// exclusing dotenv config from production
if (process.env.NODE_ENV !== 'production') require('dotenv').config()
// CORS Middleware
app.use(cors());
// express middleware handling the body parsing
app.use(express.json());
// express middleware handling the form parsing
app.use(express.urlencoded({extended: false}));
// middleware for handling sample api routes
app.use('/api/v1', require('./routes/api/route'));
// create static assets from react code for production only
if (process.env.NODE_ENV === 'production') {
app.use(express.static( 'client/build' ));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});
}
// use port from environment variables for production
const PORT = process.env.PORT || 5000;
app.listen(PORT,()=>{
console.log(`server running on port ${PORT}`);
})
module.exports = app;