Setup production environment

This commit is contained in:
thepaperpilot 2024-02-12 07:49:13 -06:00
parent 7480da4b69
commit 87b759ee77
7 changed files with 50 additions and 25 deletions

2
.gitignore vendored
View file

@ -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

View file

@ -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"]

BIN
bun.lockb

Binary file not shown.

2
client

@ -1 +1 @@
Subproject commit 337d394fd33496d9aff23ef847ce56b1464deee6
Subproject commit 616163ad796cc91d2e7077fef629fea932dd9d82

View file

@ -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"
}
}

View file

@ -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}`

18
server/package.json Normal file
View file

@ -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"
}