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 ( + <> +

Temp

+ This page is: + + + ); +} diff --git a/app/pages/test/+Page.mdx b/app/pages/test/+Page.mdx index 2347f82..dc3a29d 100644 --- a/app/pages/test/+Page.mdx +++ b/app/pages/test/+Page.mdx @@ -1,4 +1,4 @@ -import {Button} from "./Button"; +import { Button } from "@/components/Button"; # TEST diff --git a/app/pages/test/Button.tsx b/app/pages/test/Button.tsx deleted file mode 100644 index 63d0fb0..0000000 --- a/app/pages/test/Button.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import type { JSX } from "solid-js"; - -import clsx from "clsx"; - -const variantStyles = { - primary: - "bg-violet-300 font-semibold text-slate-900 hover:bg-violet-200 focus:outline-hidden focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-300/50 active:bg-violet-500", - secondary: - "bg-slate-800 font-medium text-white hover:bg-slate-700 focus:outline-hidden focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white/50 active:text-slate-400", - ghost: - "bg-transparent font-medium text-slate-900 dark:text-slate-400 hover:bg-slate-100 focus:outline-hidden focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-slate-300/50 active:bg-slate-200", -}; - -const sizeStyles = { - sm: "rounded-md py-1 px-2 text-xs", - md: "rounded-full py-2 px-4 text-sm", - lg: "rounded-full py-3 px-6 text-base", -}; - -type ButtonProps = { - variant?: keyof typeof variantStyles; - size?: keyof typeof sizeStyles; - className?: string; -} & ( - | JSX.IntrinsicElements["button"] - | (JSX.IntrinsicElements["a"] & { href: string }) -); - -export function Button({ - variant = "primary", - size = "md", - className, - ...props -}: ButtonProps) { - className = clsx( - variantStyles[variant], - sizeStyles[size], - "cursor-pointer", - className, - ); - - return ( -