-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathserver.js
37 lines (29 loc) · 943 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
const express = require('express')
const history = require('connect-history-api-fallback')
const api = require('./api')
const compression = require('compression')
const app = express()
const port = process.env.PORT || 3000
const isProduction = process.env.NODE_ENV === 'production'
if( isProduction ) {
app.use(compression())
}
app.get('/api/rooms/:room', api.getRoom)
// Quickly book a room for 15'. No args needed (for the time being)
app.post('/api/rooms/:room', api.quickBook)
app.post('/api/rooms/:room/:start/:end', api.quickBook)
app.delete('/api/rooms/:room/:eventId', api.removeBooking)
app.use(history())
if( isProduction ) {
app.use(express.static('dist'))
} else {
app.use(express.static('public'))
app.use(require('nwb/express')(express))
}
app.listen(port, (err) => {
if (err) {
console.error("Error starting server:\n", err.stack)
process.exit(1)
}
console.log('API available at port '+ port);
});