SPA option added
This commit is contained in:
@ -16,6 +16,7 @@ const _ = require('koa-route')
|
||||
const mount = require('koa-mount')
|
||||
const httpProxy = require('http-proxy')
|
||||
const pathToRegexp = require('path-to-regexp')
|
||||
const send = require('koa-send')
|
||||
|
||||
/**
|
||||
* @module local-web-server
|
||||
@ -125,6 +126,7 @@ function getApp (options) {
|
||||
/* serve static files */
|
||||
if (options.static.root) {
|
||||
app.use(serve(options.static.root, options.static.options))
|
||||
|
||||
// options.static.root.forEach(config => {
|
||||
// app.use(mount(config.route, serve(config.root)))
|
||||
// app.use(mount(config.route, serveIndex(config.root)))
|
||||
@ -136,6 +138,12 @@ function getApp (options) {
|
||||
app.use(serveIndex(options.serveIndex.path, options.serveIndex.options))
|
||||
}
|
||||
|
||||
/* for any URL not matched by static (e.g. `/search`), serve the SPA */
|
||||
if (options.spa) {
|
||||
app.use(_.all('*', function * () {
|
||||
yield send(this, options.spa, { root: process.cwd() })
|
||||
}))
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user