2020-03-11 17:42:19 +01:00
|
|
|
const { getAppRelativePath } = require("./helpers")
|
|
|
|
|
2020-03-10 11:05:09 +01:00
|
|
|
const send = require("koa-send")
|
|
|
|
|
|
|
|
module.exports = async (ctx, next) => {
|
2020-03-11 17:42:19 +01:00
|
|
|
const path = getAppRelativePath(ctx.params.appname, ctx.path)
|
2020-03-10 11:05:09 +01:00
|
|
|
|
|
|
|
if (path.startsWith("/api/")) {
|
|
|
|
await next()
|
|
|
|
} else if (path.startsWith("/_shared/")) {
|
|
|
|
await send(ctx, path.replace(`/_shared/`, ""), { root: ctx.sharedPath })
|
|
|
|
} else if (
|
|
|
|
path.endsWith(".js") ||
|
|
|
|
path.endsWith(".map") ||
|
|
|
|
path.endsWith(".css")
|
|
|
|
) {
|
|
|
|
await send(ctx, path, { root: ctx.publicPath })
|
|
|
|
} else {
|
|
|
|
await send(ctx, "/index.html", { root: ctx.publicPath })
|
|
|
|
}
|
|
|
|
}
|