nfp_sites/nfp_is/api/serve.mjs

21 lines
531 B
JavaScript
Raw Normal View History

2023-11-05 05:37:29 +00:00
import path from 'path'
import Parent from '../base/serve.mjs'
import fs from 'fs/promises'
import config from '../base/config.mjs'
export default class ServeHandler extends Parent {
loadTemplate(indexFile) {
this.template = indexFile.toString()
}
async serveIndex(ctx) {
if (config.get('NODE_ENV') === 'development') {
let indexFile = await fs.readFile(path.join(this.root, 'index.html'))
this.loadTemplate(indexFile)
}
ctx.body = this.template
ctx.type = 'text/html; charset=utf-8'
}
}