waibu-mpa
Version:
MPA support for Waibu Framework
26 lines (24 loc) • 994 B
JavaScript
const component = {
method: 'POST',
noCacheReq: true,
handler: async function (req, reply) {
const { merge, get } = this.app.lib._
req.referer = req.headers['x-referer']
const pageId = req.headers['x-req-id']
const { ext = '.html' } = req.body
let params = req.query
reply.header('Content-Type', `text/html; charset=${this.config.page.charset}`)
reply.header('Content-Language', req.lang)
if (pageId) {
try {
const locals = await this.app.cache.load(`${this.ns}.req:/${pageId}-locals.json`, this.config.reqTtlDur)
params = merge({}, locals ?? {}, params)
} catch (err) {}
}
const theme = get(req, 'headers.x-theme', get(params, '_meta.theme.name'))
const iconset = get(req, 'headers.x-iconset', get(params, '_meta.iconset.name'))
const opts = { pageId, req, reply, partial: true, ext, theme, iconset }
return this.renderString(req.body, params, opts)
}
}
export default component