From f0321ad9bbd18cb4a96573a395183b5e79de0bf2 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Fri, 8 Dec 2023 16:50:25 -1000 Subject: [PATCH] feat: Add better homepage to Lysand when started at / --- index.ts | 41 ++++++++++++++++++----------------------- pages/Home.vue | 44 ++++++++++++++++++++++++++++++++++++++++++++ pages/routes.ts | 3 +-- pages/vite.config.ts | 5 +++++ 4 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 pages/Home.vue diff --git a/index.ts b/index.ts index 1b0a7c5c..8a8b924e 100644 --- a/index.ts +++ b/index.ts @@ -124,37 +124,32 @@ Bun.serve({ return await (await file).default(req.clone(), matchedRoute, auth); } else { - // Check if path matches Vite routes - if ( - routes.find(route => route.path === new URL(req.url).pathname) - ) { - // Proxy response from Vite at localhost:5173 if in development mode - if (isProd) { - // Serve from pages/dist + // Proxy response from Vite at localhost:5173 if in development mode + if (isProd) { + if (new URL(req.url).pathname.startsWith("/assets")) { + // Serve from pages/dist/assets return new Response( // @ts-expect-error Custom Bun extension - Bun.file(`./pages/dist/index.html`) + Bun.file(`./pages/dist${new URL(req.url).pathname}`) ); - } else { - const proxy = await fetch( - req.url.replace( - config.http.base_url, - "http://localhost:5173" - ) - ); - - if (proxy.status !== 404) { - return proxy; - } } - } - if (new URL(req.url).pathname.startsWith("/assets")) { - // Serve from pages/dist/assets + // Serve from pages/dist return new Response( // @ts-expect-error Custom Bun extension - Bun.file(`./pages/dist${new URL(req.url).pathname}`) + Bun.file(`./pages/dist/index.html`) ); + } else { + const proxy = await fetch( + req.url.replace( + config.http.base_url, + "http://localhost:5173" + ) + ); + + if (proxy.status !== 404) { + return proxy; + } } return new Response(undefined, { diff --git a/pages/Home.vue b/pages/Home.vue new file mode 100644 index 00000000..0c65d837 --- /dev/null +++ b/pages/Home.vue @@ -0,0 +1,44 @@ + + + \ No newline at end of file diff --git a/pages/routes.ts b/pages/routes.ts index 003ee65f..5d08d144 100644 --- a/pages/routes.ts +++ b/pages/routes.ts @@ -1,6 +1,5 @@ import Login from "./login.vue"; - -const Home = { template: "
Home
" }; +import Home from "./Home.vue"; export default [ { path: "/", component: Home }, diff --git a/pages/vite.config.ts b/pages/vite.config.ts index 95074a01..dd23d757 100644 --- a/pages/vite.config.ts +++ b/pages/vite.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from "vite"; import UnoCSS from "unocss/vite"; import vue from "@vitejs/plugin-vue"; +import pkg from "../package.json"; export default defineConfig({ base: "/", @@ -18,6 +19,10 @@ export default defineConfig({ clientPort: 5173, }, }, + define: { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + __VERSION__: JSON.stringify(pkg.version), + }, ssr: { noExternal: ["@prisma/client"], },