nfp_sites/filadelfia_archive/api/serve.mjs

24 lines
611 B
JavaScript
Raw Permalink Normal View History

2023-11-09 09:44:04 +00:00
import fs from 'fs/promises'
import dot from 'dot'
import Parent from '../base/serve.mjs'
import path from 'path'
export default class ServeHandler extends Parent {
loadTemplate(indexFile) {
this.template = dot.template(indexFile.toString(), { argName: [
'siteUrl',
] })
}
async serveIndex(ctx) {
if (process.env.NODE_ENV !== 'production') {
let indexFile = await fs.readFile(path.join(this.root, 'index.html'))
this.loadTemplate(indexFile)
}
ctx.body = this.template({
siteUrl: this.frontend + ctx.url,
})
ctx.type = 'text/html; charset=utf-8'
}
}