diff --git a/app/fastify-server.ts b/app/fastify-server.ts new file mode 100644 index 0000000..0654742 --- /dev/null +++ b/app/fastify-server.ts @@ -0,0 +1,46 @@ +import { fileURLToPath } from "node:url"; +import { dirname } from "node:path"; +import { config } from "./config"; +import Fastify from "fastify"; +import fs from "node:fs"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const root = __dirname; + +const pagesDir = `${root}/dist/client`; + +async function startServer() { + const app = Fastify(); + + await app.register(await import("@fastify/static"), { + root: `${root}/dist/client`, + wildcard: false, + }); + + app.get("/*", (request, reply) => { + const filePath = `${pagesDir}${request.url}/index.html`; + + if (!fs.existsSync(filePath)) { + const stream = fs.createReadStream(`${pagesDir}/404.html`); + reply.status(404).type("text/html").send(stream); + return; + } + + const stream = fs.createReadStream(filePath); + reply.type("text/html").send(stream); + }); + + return app; +} + +const app = await startServer(); + +app.listen({ port: config.PORT, host: "0.0.0.0" }, (error, address) => { + if (error) { + app.log.error(error); + process.exit(1); + } + + console.log(`Server listening on ${address}`); +}); diff --git a/app/package.json b/app/package.json index 9944b6e..ecdcdb1 100755 --- a/app/package.json +++ b/app/package.json @@ -1,8 +1,8 @@ { "scripts": { "dev": "bun ./fastify-entry.ts", - "build": "vike build", - "preview": "cross-env NODE_ENV=production bun ./fastify-entry.ts", + "build": "cross-env DEBUG=vike:error,vike:log vike build", + "preview": "cross-env NODE_ENV=production bun ./fastify-server.ts", "production": "bun run build && bun run preview", "lint": "biome lint --write .", "format": "biome format --write ." diff --git a/app/pages/temp/+Page.tsx b/app/pages/temp/+Page.tsx new file mode 100755 index 0000000..459d05c --- /dev/null +++ b/app/pages/temp/+Page.tsx @@ -0,0 +1,11 @@ +export default function Page() { + return ( + <> +