-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
40 lines (30 loc) · 854 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
39
40
const bodyParser = require('body-parser')
const path = require('path')
const app = require("./api/app")
const express = require("express")
app.use(bodyParser.json());
app.use(express.static('client/build'))
app.use(express.static('dashboard/build'))
app.get('/api/*',(req,res) =>{
console.log("dashboard sendfile")
res.sendFile(path.resolve(__dirname,'dashboard','build','index.html'))
})
app.get('*',(req,res) =>{
res.sendFile(path.resolve(__dirname,'client','build','index.html'))
})
app.use((req,res,next)=>{
const error = new Error("Not Found")
error.status = 404
next(error)
})
app.use((error,req,res,next)=>{
res.status(error.status||500)
res.json({
error:{
message : error.message
}
})
})
const PORT = process.env.PORT
app.listen(PORT)
console.log("Listening at 4000 port")