-
Notifications
You must be signed in to change notification settings - Fork 13
/
mock.js
29 lines (23 loc) · 690 Bytes
/
mock.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
'use strict'
const koa = require('koa')
const logger = require('koa-logger')
const route = require('koa-route')
const fs = require('fs')
const staticCache = require('koa-static-cache')
const mount = require('koa-mount')
const app = koa()
const backendPort = 3000
let deploy = 'examples'
app.use(logger())
app.use(mount('/', staticCache(__dirname)))
app.use(route.get('*', function* () {
this.type = 'html'
this.body = yield function (done) {
fs.readFile(`${deploy}/build/index.html`, 'utf8', done)
}
}))
app.listen(backendPort, function () {
/* eslint-disable no-console */
console.log(`Backend Koa Server Listen At: ${backendPort}`)
/* eslint-enable no-console */
})