|
@ -164,6 +164,17 @@ function localWebServer (options) { |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
/* for any URL not matched by static (e.g. `/search`), serve the SPA */ |
|
|
|
|
|
if (options.spa) { |
|
|
|
|
|
const historyApiFallback = require('koa-connect-history-api-fallback'); |
|
|
|
|
|
debug('SPA', options.spa) |
|
|
|
|
|
app.use(historyApiFallback({ |
|
|
|
|
|
index: options.spa, |
|
|
|
|
|
verbose: options.verbose, |
|
|
|
|
|
rewrites: options.rewrite |
|
|
|
|
|
})); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* serve static files */ |
|
|
/* serve static files */ |
|
|
if (options.static.root) { |
|
|
if (options.static.root) { |
|
|
const serve = require('koa-static') |
|
|
const serve = require('koa-static') |
|
@ -176,15 +187,6 @@ function localWebServer (options) { |
|
|
app.use(serveIndex(options.serveIndex.path, options.serveIndex.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) { |
|
|
|
|
|
const send = require('koa-send') |
|
|
|
|
|
debug('SPA', options.spa) |
|
|
|
|
|
app.use(_.all('*', function spa (ctx, route, next) { |
|
|
|
|
|
const root = path.resolve(options.static.root) || process.cwd() |
|
|
|
|
|
return send(ctx, options.spa, { root: root }).then(next) |
|
|
|
|
|
})) |
|
|
|
|
|
} |
|
|
|
|
|
return app |
|
|
return app |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|