mirror of
https://github.com/kou029w/quot.git
synced 2025-01-19 00:18:09 +00:00
34 lines
808 B
TypeScript
34 lines
808 B
TypeScript
|
import type { FastifyInstance } from "fastify";
|
||
|
import httpProxy from "@fastify/http-proxy";
|
||
|
import esbuild from "esbuild";
|
||
|
|
||
|
async function views(fastify: FastifyInstance) {
|
||
|
const viewsDir = fastify.config.viewsDir;
|
||
|
const entryPoint = `${viewsDir}/index.ts`;
|
||
|
const { host, port } = await esbuild.serve(
|
||
|
{
|
||
|
host: "127.0.0.1",
|
||
|
servedir: viewsDir,
|
||
|
},
|
||
|
{
|
||
|
bundle: true,
|
||
|
minify: true,
|
||
|
entryPoints: [entryPoint],
|
||
|
define: {
|
||
|
"import.meta.env.QUOT_API_ENDPOINT": JSON.stringify(
|
||
|
fastify.config.apiEndpoint
|
||
|
),
|
||
|
},
|
||
|
}
|
||
|
);
|
||
|
|
||
|
await fastify.register(httpProxy, {
|
||
|
upstream: `http://${host}:${port}`,
|
||
|
async preHandler(req) {
|
||
|
if (!/\.(?:html|css|js)$/.test(req.url)) req.raw.url = "/";
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export default views;
|