"use strict"; const Koa = require("koa"); const app = new Koa(); const helmet = require("koa-helmet"); const actions = require("./actions.js"); const responders = require("./responders.js"); const config = require("./modules/config.js"); const Router = require("koa-router"); const router = new Router(); const makeTagURI = (authority, startDate) => specific => `tag:${authority},${startDate}:${specific}`; app.context.makeTagURI = makeTagURI( config.feed.originalDomainName, config.feed.domainStartDate ); app.context.getURL = router.url.bind(router); module.exports = async function() { const Posts = await require("./domain/posts.js")(config.posts, basename => router.url("post", basename) ); router.get("home", "/", actions.home(config, responders.home, Posts.posts)); router.get( "posts", "/post", actions.posts(config, responders.list, Posts.posts) ); router.get( "highlight-theme", "/css/code.css", actions.highlightTheme(config) ); router.get( "feed", "/index.xml", actions.posts(config, responders.feed, Posts.posts) ); router.get( "post", "/post/:filename", actions.post(config, responders.post, Posts.posts) ); router.get( "tag", "/tag/:name", actions.tag(config, responders.list, Posts.tags) ); app.use( helmet({ hsts: { setIf: ctx => ctx.secure } }) ); app.use(router.routes()).use(router.allowedMethods()); app.use(actions.serveFiles); return app; };