-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (26 loc) · 781 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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require("express")
const path = require("path")
const app = express()
// JUST FOR DEMO PURPOSES, PUT YOUR ACTUAL API CODE HERE
app.get('/api/demo', (request, response) => {
response.json({
message: "Hello from server.js"
})
})
// END DEMO
if (process.env.NODE_ENV === 'production') {
// Serve any static files
app.use(express.static(path.join(__dirname, 'client/build')))
// Handle React routing, return all requests to React app
app.get('*', (request, response) => {
response.sendFile(path.join(__dirname, 'client/build', 'index.html'))
})
}
const port = process.env.PORT || 8080
app.listen(
port,
() => { console.log(`API listening on port ${port}...`) }
)