2022-08-23 20:08:53 +02:00
|
|
|
import { promises as fs } from "graceful-fs";
|
2020-04-09 20:18:13 +02:00
|
|
|
|
|
|
|
import ErrorTypes from "../utils/errorTypes";
|
|
|
|
import Logger from "../logger";
|
|
|
|
import * as Resources from "../utils/resources";
|
2022-09-14 16:33:43 +02:00
|
|
|
import type { Request, Response } from "express";
|
2020-04-09 20:18:13 +02:00
|
|
|
|
2022-08-23 20:08:53 +02:00
|
|
|
const indexHtml = __dirname + "/../../client/index.html";
|
2020-04-09 20:18:13 +02:00
|
|
|
|
2022-08-23 20:08:53 +02:00
|
|
|
export function render(req: Request, res: Response): void {
|
2020-04-09 20:18:13 +02:00
|
|
|
const data = Resources.getData(req);
|
|
|
|
|
2022-08-23 20:08:53 +02:00
|
|
|
fs.readFile(indexHtml, "utf8")
|
|
|
|
.then((body) =>
|
2020-04-09 20:18:13 +02:00
|
|
|
Resources.successHtml(
|
|
|
|
res,
|
|
|
|
body.replace(
|
|
|
|
/<body/,
|
2022-08-23 20:08:53 +02:00
|
|
|
"<script>window.__nodeToken = '" +
|
|
|
|
data.token +
|
|
|
|
"';</script><body"
|
2020-04-09 20:18:13 +02:00
|
|
|
)
|
2022-08-23 20:08:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
.catch((err) => {
|
|
|
|
Logger.tag("frontend").error(
|
|
|
|
"Could not read file: ",
|
|
|
|
indexHtml,
|
|
|
|
err
|
|
|
|
);
|
|
|
|
return Resources.error(res, {
|
|
|
|
data: "Internal error.",
|
|
|
|
type: ErrorTypes.internalError,
|
|
|
|
});
|
|
|
|
});
|
2020-04-09 20:18:13 +02:00
|
|
|
}
|