-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (21 loc) · 772 Bytes
/
server.js
File metadata and controls
27 lines (21 loc) · 772 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
const express = require('express');
const path = require('path')
// server app
const tv = require('./routes/api/tv')
const app = express()
app.use(express.json());
app.use(express.urlencoded({extended:false}));
// use Routes
app.use('/api/tv', tv);
// if none of these api routes are being hit, look for index
// Server static assets if in production
if(process.env.NODE_ENV === 'production') {
// Set static folder to client/build
app.use(express.static('client/build'));
// any route gets hit here load the react html file in build
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
const port = process.env.PORT || 3333;
app.listen(port, () => console.log(`Server running on port ${port}`));