SPA option added

This commit is contained in:
Lloyd Brookes
2015-11-15 14:53:25 +00:00
parent b42e5f3918
commit 99305cb78a
7 changed files with 32 additions and 3 deletions

View File

@ -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
}