@trifrost/core
Version:
Blazingly fast, runtime-agnostic server framework for modern edge and node environments
30 lines (29 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mount = mount;
const types_1 = require("../../../types");
const Engine_1 = require("./Engine");
const use_1 = require("./use");
const Generic_1 = require("../../../utils/Generic");
function mount(router, path, module) {
/* We cache root content in mem*/
let content;
/* Set mount path on module */
module.setMountPath(path);
router.get(path, ctx => {
if (!content) {
const style_engine = (0, use_1.setActiveStyleEngine)(new Engine_1.StyleEngine());
/* We wrap in setMountPath(path) and setMountPath(null) to tell the module we're rendering our mounted parts */
module.setMountPath(null);
module.root();
module.setMountPath(path);
content = style_engine.flush({ mode: 'file' });
(0, use_1.setActiveStyleEngine)(null);
}
/* Set css mime */
ctx.setType(types_1.MimeTypes.CSS);
return ctx.text(content,
/* If not in dev mode add cache control */
!(0, Generic_1.isDevMode)(ctx.env) ? { status: 200, cacheControl: { type: 'public', maxage: 86400, immutable: true } } : { status: 200 });
});
}