From d2b9b7e3299a4d80655439c99c5de26a8c95e6f2 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 19 Jun 2017 21:06:49 +0200 Subject: feat: Serve static files under ./static --- src/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 6622a79..8c69cc8 100644 --- a/src/index.js +++ b/src/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 @@ -59,6 +61,15 @@ for (let [term, items] of taxonomies) { 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 if (require.main === module) { -- cgit 1.4.1