-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (26 loc) · 717 Bytes
/
index.js
File metadata and controls
31 lines (26 loc) · 717 Bytes
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 Koa = require('koa')
const app = new Koa()
const mount = require('koa-mount')
const config = require('./config.js')()
// The root application
const rootApp = new Koa()
rootApp.use(async (ctx, next) => {
await next()
ctx.body = 'Find the APIs under /user, /order and /address respectively'
})
// APIS
const userApi = require('UserAPI').app
const addressApi = require('AddressAPI').app
const orderApi = require('OrderAPI').app
// Mounting
app.use(mount('/users', userApi))
app.use(mount('/address', addressApi))
app.use(mount('/orders', orderApi))
app.use(mount('/', rootApp))
if (!module.parent) {
app.listen(config.port)
console.log('listening on port ' + config.port)
}
module.exports = {
app
}