"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-expect-error -- vite uses "exports" which requires moduleResolution: "bundler"
const vite_1 = require("vite");
const fs_1 = __importDefault(require("fs"));
const log_1 = __importDefault(require("../log"));
const rootpath_1 = __importDefault(require("../rootpath"));
const html_config_1 = require("./html-config");
exports.default = async (app) => {
    log_1.default.debug("Starting server in development mode");
    const vite = await (0, vite_1.createServer)({
        configFile: (0, rootpath_1.default)("vite.config.ts"),
        server: { middlewareMode: true },
        appType: "custom",
    });
    app.use(vite.middlewares);
    // eslint-disable-next-line @typescript-eslint/no-misused-promises
    app.get("/", async (req, res) => {
        const rawHtml = fs_1.default.readFileSync((0, rootpath_1.default)("client", "index.html"), "utf-8");
        const html = await vite.transformIndexHtml(req.url, rawHtml);
        res.setHeader("Content-Type", "text/html");
        res.send((0, html_config_1.injectServerConfig)(html));
    });
};
