diff --git a/.gitignore b/.gitignore index 919c740..2aff449 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules +**/node_modules /.pnp .pnp.js diff --git a/Dockerfile b/Dockerfile index 2909a35..281881f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,22 @@ FROM oven/bun +# Build client +WORKDIR /app/client +COPY client . +RUN bun install +RUN bunx --bun vite build + WORKDIR /app -COPY package.json . -COPY bun.lockb . +RUN mv client/build public +RUN rm -rf client + +COPY server src +RUN mv src/package.json package.json +COPY tsconfig.json . RUN bun install --production -COPY src src -COPY tsconfig.json . -# COPY public public - ENV NODE_ENV production CMD ["bun", "src/index.ts"] diff --git a/bun.lockb b/bun.lockb index de1405c..6441e49 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/client b/client index 337d394..616163a 160000 --- a/client +++ b/client @@ -1 +1 @@ -Subproject commit 337d394fd33496d9aff23ef847ce56b1464deee6 +Subproject commit 616163ad796cc91d2e7077fef629fea932dd9d82 diff --git a/package.json b/package.json index a942226..b7e8466 100644 --- a/package.json +++ b/package.json @@ -3,22 +3,15 @@ "version": "1.0.0", "private": true, "scripts": { - "start": "bun run server/index.ts", "dev": "conc npm:dev:server npm:dev:client", "dev:server": "bun run --watch server/index.ts", "dev:client": "bunx --bun vite client", "build": "bunx --bun vite build client", - "test": "vitest run -r client", - "testw": "vitest -r client" + "test": "bunx --bun vitest run -r client", + "testw": "bunx --bun vitest -r client" }, "dependencies": { - "@bogeychan/elysia-oauth2": "^0.0.19", - "elysia": "latest", - "profectus": "file:./client" - }, - "devDependencies": { - "bun-types": "latest", - "concurrently": "^8.2.2" - }, - "module": "server/index.js" + "client": "file:./client", + "server": "file:./server" + } } diff --git a/server/index.ts b/server/index.ts index e8b7ff1..3185a00 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1,11 +1,11 @@ -import { Elysia, t } from "elysia"; import oauth2 from "@bogeychan/elysia-oauth2"; +import { staticPlugin } from '@elysiajs/static'; import { Database } from "bun:sqlite"; import { randomBytes } from "crypto"; +import { Elysia, t } from "elysia"; - -import { migrateDatabase } from "./migrations"; import { clientToServerEvents } from "../common/events"; +import { migrateDatabase } from "./migrations"; const db = new Database("db.sqlite", { create: true }); migrateDatabase(db); @@ -101,8 +101,16 @@ const app = new Elysia() // Update avatar and display name from mbin, fallback to userinfo } - }) - .listen(3000); + }); + +if (Bun.env.NODE_ENV === "production") { + app.use(staticPlugin({ + alwaysStatic: true, + prefix: "" + })); +} + +app.listen(3000); console.log( `🦊 Chromatic Lattice server is running at ${app.server?.url.href}` diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..639f23f --- /dev/null +++ b/server/package.json @@ -0,0 +1,18 @@ +{ + "name": "chromatic-lattice-server", + "version": "1.0.0", + "private": true, + "scripts": { + "start": "bun run server/index.ts" + }, + "dependencies": { + "@bogeychan/elysia-oauth2": "^0.0.19", + "@elysiajs/static": "^0.8.1", + "elysia": "latest" + }, + "devDependencies": { + "bun-types": "latest", + "concurrently": "^8.2.2" + }, + "module": "server/index.js" +}