-
Notifications
You must be signed in to change notification settings - Fork 34
/
server.js
48 lines (39 loc) · 1.41 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const path = require('path')
const morgan = require('morgan')
const port = process.env.PORT || 5000
// Import routes
const infixToPostfixRoutes = require('./routes/infixToPostfixRoutes')
const postfixToInfixRoutes = require('./routes/postfixToInfixRoutes')
const infixToPrefixRoutes = require('./routes/infixToPrefixRoutes')
const prefixToInfixRoutes = require('./routes/prefixToInfixRoutes')
const prefixToPostfixRoutes = require('./routes/prefixToPostfixRoutes')
const postfixToPrefixRoutes = require('./routes/postfixToPrefixRoutes')
const app = express()
app.use(cors())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
app.use(bodyParser.json())
app.use(morgan('dev'))
app.use('/api/', infixToPostfixRoutes)
app.use('/api/', postfixToInfixRoutes)
app.use('/api/', infixToPrefixRoutes)
app.use('/api/', prefixToInfixRoutes)
app.use('/api/', prefixToPostfixRoutes)
app.use('/api/', postfixToPrefixRoutes)
if (process.env.NODE_ENV === 'production') {
// Exprees will serve up production assets
app.use(express.static('ui/build'))
// Express serve up index.html file if it doesn't recognize route
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'ui', 'build', 'index.html'))
})
}
app.listen(port, () => {
console.log(`Server started on port ${port}`)
})