import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js"; import Page from "@entity-access/server-pages/dist/Page.js"; import ChannelPageService from "../../../server/services/channels/ChannelPageService.js"; import SSRService from "../../../server/services/ssr/SSRService.js"; import WebSiteContentService from "../../../server/services/files/WebSiteContentService.js"; export default class extends Page { @Inject websiteService: WebSiteContentService; @Inject channelPageService: ChannelPageService; async run() { // we will check for bot if ( this.request.query.ssr === "true" || /bot/i.test(this.request.headers["user-agent"])) { if (this.request.query.ssr !== "disable") { const url = this.request.URL; url.searchParams.delete("ssr"); url.searchParams.set("ssr", "disable"); const ssr = ServiceProvider.resolve(this, SSRService); const tf = await ssr.generate(url.toString()); const body = await tf.readAsText(); return this.content({ body, contentType: "text/html" }); } } const host = this.request.host; const appFile = await this.websiteService.getNamedPageContent(host, ["blog.html", "channel.html"]); if (!appFile) { return this.notFound(); } const { meta } = await this.channelPageService.getMeta(host, this.request.URL.toString(), this.childPath as any); let body = await appFile.readAsText(); if (meta?.length) { body = body.replace(/\]*\>/, (s, v) => { return s + meta.map((x) => x.render()).join("\r\n"); }); } // const body = await this.channelPageService.modifyPage({ // host, // url: this.request.URL.toString(), // blogID, // type, // emailID, // file // }); this.cacheControl = "public, max-age=8600, immutable"; return this.content({ body, contentType: "text/html" }); } }