first commit

This commit is contained in:
Shotaro Nakamura
2026-06-18 22:59:53 +09:00
commit 20434dcd11
88 changed files with 13950 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
FROM oven/bun:1 AS deps
WORKDIR /app
COPY package.json bun.lock tsconfig.json vite.config.ts ./
COPY packages/sbi-client/package.json packages/sbi-client/package.json
COPY apps/csbie/package.json apps/csbie/package.json
COPY apps/csbie-server/package.json apps/csbie-server/package.json
COPY apps/csbie-ui/package.json apps/csbie-ui/package.json
RUN bun install --frozen-lockfile
FROM deps AS build
COPY . .
RUN bun --filter @repo/csbie build
FROM oven/bun:1-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/apps/csbie/dist ./apps/csbie/dist
COPY --from=build /app/apps/csbie-ui/dist ./apps/csbie-ui/dist
COPY --from=build /app/node_modules ./node_modules
EXPOSE 8787
CMD ["bun", "apps/csbie/dist/index.js"]
+20
View File
@@ -0,0 +1,20 @@
{
"name": "@repo/csbie",
"private": true,
"type": "module",
"scripts": {
"clean": "rm -rf dist ../csbie-ui/dist",
"dev": "bun --env-file=../../.env src/dev.ts",
"build": "bun --filter @repo/csbie-ui build && bun build src/index.ts --target=bun --outdir=dist",
"start": "bun --env-file=../../.env dist/index.js",
"typecheck": "tsc"
},
"dependencies": {
"@repo/csbie-server": "workspace:*",
"hono": "^4.8.3"
},
"devDependencies": {
"@types/bun": "latest",
"typescript": "^5"
}
}
+37
View File
@@ -0,0 +1,37 @@
const uiPort = Number(process.env.CSBIE_UI_DEV_PORT ?? 5173)
const serverPort = Number(process.env.PORT ?? process.env.CSBIE_SERVER_PORT ?? 8787)
const uiOrigin = `http://127.0.0.1:${uiPort}`
const serverEntry = new URL('../../csbie-server/src/index.ts', import.meta.url).pathname
const ui = Bun.spawn({
cmd: ['bun', '--filter', '@repo/csbie-ui', 'dev'],
stdout: 'inherit',
stderr: 'inherit',
stdin: 'inherit',
env: process.env,
})
const server = Bun.spawn({
cmd: ['bun', '--watch', serverEntry],
stdout: 'inherit',
stderr: 'inherit',
stdin: 'inherit',
env: {
...process.env,
PORT: String(serverPort),
CSBIE_ORIGIN: uiOrigin,
CSBIE_CORS_ORIGIN: uiOrigin,
},
})
const shutdown = () => {
ui.kill()
server.kill()
}
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)
const appExit = await server.exited
shutdown()
process.exit(appExit)
+55
View File
@@ -0,0 +1,55 @@
import { existsSync } from 'node:fs'
import { extname, join } from 'node:path'
import { Hono } from 'hono'
import { createServerApp } from '@repo/csbie-server/app'
import { loadConfig } from '@repo/csbie-server/config'
import { createDb } from '@repo/csbie-server/db'
const config = loadConfig()
const db = createDb(config.databasePath)
const api = createServerApp(db, config)
const app = new Hono()
const uiDist = join(import.meta.dir, '../../csbie-ui/dist')
const contentTypes: Record<string, string> = {
'.css': 'text/css; charset=utf-8',
'.html': 'text/html; charset=utf-8',
'.js': 'text/javascript; charset=utf-8',
'.json': 'application/json; charset=utf-8',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
}
app.route('/api', api.app)
app.route('/', api.app)
const serveUi = async (request: Request) => {
const url = new URL(request.url)
const pathname = decodeURIComponent(url.pathname)
const relativePath = pathname === '/' ? 'index.html' : pathname.slice(1)
const filePath = join(uiDist, relativePath)
const resolvedPath = existsSync(filePath) ? filePath : join(uiDist, 'index.html')
const file = Bun.file(resolvedPath)
const headers = new Headers()
headers.set('content-type', contentTypes[extname(resolvedPath)] ?? 'application/octet-stream')
return new Response(file, { headers })
}
const server = Bun.serve({
port: config.port,
fetch(request, server) {
const url = new URL(request.url)
if (
url.pathname.startsWith('/api/') ||
url.pathname.startsWith('/.well-known/') ||
url.pathname.startsWith('/oauth/') ||
['/authorize', '/token', '/register', '/revoke'].includes(url.pathname)
) {
return app.fetch(request, { server })
}
return serveUi(request)
},
websocket: api.websocket,
})
console.log(`csbie listening on http://localhost:${server.port}`)
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["bun"],
"rootDir": "src",
"outDir": "dist",
"noEmit": true
},
"include": ["src/**/*.ts"]
}