-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·31 lines (26 loc) · 873 Bytes
/
index.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
const dispatch = require('micro-route/dispatch')
const next = require('next')
const moduleAlias = require('module-alias')
const getNearestLineStop = require('./routes/getNearestLineStop')
const getStopStatus = require('./routes/getStopStatus')
const getAllLines = require('./routes/getAllLines')
const dev = process.env.NODE_ENV !== 'production'
if (!dev) {
moduleAlias.addAlias('react', 'preact-compat')
moduleAlias.addAlias('react-dom', 'preact-compat')
}
const app = next({dev})
const handle = app.getRequestHandler()
var nextReady = false
app.prepare().then(() => {
nextReady = true
})
module.exports = dispatch()
.dispatch('/api/lines', ['GET'], getAllLines)
.dispatch('/api/stop/locate', ['POST'], getNearestLineStop)
.dispatch('/api/stop', ['POST'], getStopStatus)
.otherwise((req, res) => {
if (nextReady) {
handle(req, res)
}
})