Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4eeb247
fix: skip vite server config during build
tknkaa May 6, 2026
b2fb46f
feat: use PUBLIC_API_URL as api base url in production
tknkaa May 6, 2026
a04c464
chore: update elysia
tknkaa May 6, 2026
defb29c
fix: explicitly set BETTER_AUTH_SECRET from env
tknkaa May 6, 2026
f71ffcf
chore: add Dockerfile and .dockerignore
tknkaa May 6, 2026
41ff9b8
chore: remove copy of web dependencies
tknkaa May 6, 2026
999f5d2
chore: not ignore web dependencies
tknkaa May 6, 2026
539ff0e
chore: copy web dependencies
tknkaa May 6, 2026
830a7a5
chore: copy tests dependencies
tknkaa May 6, 2026
bd9d648
copy server node_modules
tknkaa May 6, 2026
f0a09ba
chore: update elysia again
tknkaa May 6, 2026
7d41bfa
update lockfile
tknkaa May 6, 2026
7a3e107
specify package manager
tknkaa May 6, 2026
9f60622
change build script
tknkaa May 6, 2026
78313dd
format
tknkaa May 6, 2026
b184e35
fix
tknkaa May 6, 2026
013f4ae
skip typecheck
tknkaa May 6, 2026
a8a6f4c
fix
tknkaa May 6, 2026
2e6c9a0
fix
tknkaa May 6, 2026
81d2b7e
fix
tknkaa May 7, 2026
e3a0e0e
fix type error
tknkaa May 7, 2026
5629916
change build command
tknkaa May 7, 2026
6c0894d
refactor
tknkaa May 7, 2026
8598b75
format
tknkaa May 7, 2026
42f2516
use absolute path
tknkaa May 7, 2026
b7be62b
add frontend url to trusted origin
tknkaa May 7, 2026
b27136a
fix redirect path
tknkaa May 7, 2026
4410439
fix cors
tknkaa May 7, 2026
9692d5b
include credential
tknkaa May 7, 2026
bab2300
format
tknkaa May 7, 2026
cd6091d
proxy via pages function
tknkaa May 7, 2026
605215d
fix
tknkaa May 7, 2026
c141ca3
fix
tknkaa May 7, 2026
71fe352
use same domain
tknkaa May 7, 2026
8650964
delete worker types
tknkaa May 7, 2026
1a1e58a
add comment
tknkaa May 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/node_modules
.git
.gitignore
.env
.env.*
.DS_Store
coverage
dist
tmp
.cache
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Config
PUBLIC_MOCK_DATA=true
# Optional: set this in production when the frontend is hosted on a different origin.
# PUBLIC_FRONTEND_URL=http://localhost:3000

# 開発中 -> Vite: BASE_URL.port, Elysia: EXTERNAL_SERVER_PORT
# プロダクション -> Vite: - , Elysia: PORT ?? BASE_URL.port
BASE_URL=http://localhost:3000
EXTERNAL_SERVER_PORT=4000
FRONTEND_URL=http://localhost:3000

NODE_ENV=development

Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM oven/bun:1.3.1-alpine AS deps

WORKDIR /app

COPY package.json bun.lock ./
COPY packages/class_data/package.json ./packages/class_data/package.json
COPY packages/models/package.json ./packages/models/package.json
COPY packages/server/package.json ./packages/server/package.json
COPY packages/web/package.json ./packages/web/package.json
COPY packages/tests/package.json ./packages/tests/package.json

RUN bun install --frozen-lockfile


FROM oven/bun:1.3.1-alpine AS runner

ENV NODE_ENV=production
WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/packages/server/node_modules ./packages/server/node_modules
COPY package.json bun.lock ./
COPY packages/server ./packages/server
COPY packages/models ./packages/models
COPY packages/class_data ./packages/class_data

RUN mkdir -p /app/data
VOLUME ["/app/data"]

EXPOSE 4000

CMD ["bun", "run", "packages/server/serve.ts"]
660 changes: 357 additions & 303 deletions bun.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"concurrently": "^9.2.1"
},
"dependencies": {
"@elysiajs/eden": "^1.4.4",
"elysia": "^1.4.15"
}
"@elysiajs/eden": "1.4.9",
"elysia": "1.4.19"
},
"packageManager": "bun@1.3.11"
}
8 changes: 7 additions & 1 deletion packages/server/app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { cors } from "@elysiajs/cors";
import { Elysia } from "elysia";
import { auth, betterAuth } from "./lib/auth.ts";
import { env } from "./lib/env.ts";
import coursesRouter from "./router/courses.ts";
import usersRouter from "./router/users.ts";

export const app = new Elysia({
prefix: "/api",
})
.mount(auth.handler)
.use(cors())
.use(
cors({
origin: [env.FRONTEND_URL],
credentials: true,
}),
)
.use(betterAuth)
.use(coursesRouter)
.use(usersRouter);
Expand Down
4 changes: 3 additions & 1 deletion packages/server/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as schema from "../db/schema.ts";
import { env } from "../lib/env.ts";

export const auth = betterAuth({
secret: env.BETTER_AUTH_SECRET,
baseURL: env.BASE_URL,
database: drizzleAdapter(db, {
provider: "sqlite",
Expand All @@ -17,7 +18,7 @@ export const auth = betterAuth({
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
trustedOrigins: [env.BASE_URL],
trustedOrigins: [env.BASE_URL, env.FRONTEND_URL],
advanced: {
cookiePrefix: "x_utcode_syllabus_",
},
Expand All @@ -38,4 +39,5 @@ const betterAuthMacro = new Elysia({ name: "better-auth" }).macro({
},
},
});

export { betterAuthMacro as betterAuth };
2 changes: 2 additions & 0 deletions packages/server/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export const env = {
DATABASE_URL: e.string("DATABASE_URL"),
GOOGLE_CLIENT_ID: e.string("GOOGLE_CLIENT_ID"),
GOOGLE_CLIENT_SECRET: e.string("GOOGLE_CLIENT_SECRET"),
BETTER_AUTH_SECRET: e.string("BETTER_AUTH_SECRET"),

LISTEN_PORT: getListenPort() ?? panic("[env] Port to listen not found"),
BASE_URL: e.string("BASE_URL"),
FRONTEND_URL: e.string("FRONTEND_URL"),

PUBLIC_MOCK_DATA: e.boolean("PUBLIC_MOCK_DATA"),
};
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"@sinclair/typebox": "^0.34.38",
"better-auth": "^1.3.1",
"drizzle-orm": "^0.44.3",
"elysia": "1.4.4"
"elysia": "1.4.19"
}
}
6 changes: 3 additions & 3 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
"type": "module",
"scripts": {
"dev": "bun run --env-file=../../.env vite",
"build": "tsc && bun run --env-file=../../.env vite build",
"build": "tsc && vite build",
"preview": "vite preview",
"check": "tsc --noEmit",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@elysiajs/eden": "1.4.4",
"@elysiajs/eden": "1.4.9",
"@headlessui/react": "^2.2.4",
"@packages/models": "workspace:*",
"@packages/server": "workspace:*",
"@sinclair/typebox": "^0.34.38",
"@tanstack/react-query": "^5.83.0",
"better-auth": "^1.3.34",
"elysia": "1.4.4",
"elysia": "1.4.19",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"react-hook-form": "^7.60.0",
Expand Down
7 changes: 6 additions & 1 deletion packages/web/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { edenTreaty } from "@elysiajs/eden";
import type { App } from "@packages/server";

export const api = edenTreaty<App>(window.location.origin, {}).api;
// 開発環境だと Vite サーバーでプロキシしているから、同一オリジン
export const baseUrl = import.meta.env.PUBLIC_API_URL ?? window.location.origin;
export const frontendUrl =
import.meta.env.PUBLIC_FRONTEND_URL ?? window.location.origin;

export const api = edenTreaty<App>(baseUrl, {}).api;
8 changes: 6 additions & 2 deletions packages/web/src/lib/auth-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createAuthClient } from "better-auth/react";
import { baseUrl, frontendUrl } from "./api.ts";

export const auth = createAuthClient({
baseURL: window.location.origin,
baseURL: baseUrl,
fetchOptions: {
credentials: "include",
},
});

export async function logout() {
Expand All @@ -11,6 +15,6 @@ export async function logout() {
export async function signInWithGoogle(callbackURL: string) {
await auth.signIn.social({
provider: "google",
callbackURL,
callbackURL: new URL(callbackURL, frontendUrl).toString(),
});
}
24 changes: 14 additions & 10 deletions packages/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "node:path";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
export default defineConfig(({ command }) => ({
plugins: [react()],
resolve: {
alias: {
Expand All @@ -11,15 +11,19 @@ export default defineConfig({
},
envDir: "../../",
envPrefix: "PUBLIC_",
server: {
port: getPort(getEnv("BASE_URL")),
proxy: {
"/api": {
target: `http://localhost:${getEnv("EXTERNAL_SERVER_PORT")}`,
},
},
},
});
...(command === "serve"
? {
server: {
port: getPort(getEnv("BASE_URL")),
proxy: {
"/api": {
target: `http://localhost:${getEnv("EXTERNAL_SERVER_PORT")}`,
},
},
},
}
: {}),
}));

function getEnv(name: string): string {
const val = process.env[name];
Expand Down
Loading