all repos — archive/homestead @ d2b9b7e3299a4d80655439c99c5de26a8c95e6f2

My future indieweb platform

feat: Serve static files under ./static

Alan Pearce
commit

d2b9b7e3299a4d80655439c99c5de26a8c95e6f2

parent

7455233d74ffe056c4a5927c9272516fdc0e5dfc

1 file changed, 11 insertions(+), 0 deletions(-)

changed files
M src/index.jssrc/index.js
@@ -3,6 +3,8 @@
const Koa = require('koa') const app = new Koa() +const send = require('koa-send') + const config = require('./modules/config.js') const PORT = process.env.PORT || config.server.port
@@ -58,6 +60,15 @@ })
} app.use(router.routes()).use(router.allowedMethods()) + +const prefix = /^\/static\// +app.use(async function (ctx) { + if (prefix.test(ctx.path)) { + await send(ctx, ctx.path.replace(prefix, ''), { + root: './static' + }) + } +}) module.exports = app