diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b5f9929 --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# Database Configuration +# Use localhost for local 'bun run dev' +# docker-compose will override this with its own service name 'postgres' +DATABASE_URL=postgres://postgres:password@localhost:5432/alert_message_center + +# Feishu (Lark) App Configuration +# Make sure to ADD BOTH to your Feishu App Management console! +FEISHU_APP_ID=your_app_id +FEISHU_APP_SECRET=your_app_secret +FEISHU_VERIFICATION_TOKEN=your_verification_token +FEISHU_ENCRYPT_KEY=your_encrypt_key + +# Admin configuration (comma-separated emails) +ADMIN_EMAILS=admin@example.com + +# Optional: Frontend URL for CORS during local dev +FRONTEND_URL=http://localhost:3000 +REDIRECT_URI=http://localhost:3000/auth/callback \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d0a432 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Build stage for web +FROM oven/bun:1-alpine AS web-builder +WORKDIR /app +COPY . . +RUN bun install --frozen-lockfile +WORKDIR /app/apps/web +RUN bun run build + +# Final stage +FROM oven/bun:1-alpine +WORKDIR /app + +# Copy the entire project for monorepo context +COPY . . + +# Install dependencies for the server (and shared workspace if any) +RUN bun install --frozen-lockfile + +# Copy built web assets to server's public directory +COPY --from=web-builder /app/apps/web/dist /app/apps/server/public + +WORKDIR /app/apps/server + +EXPOSE 3000 + +CMD ["bun", "run", "start"] diff --git a/apps/server/Dockerfile b/apps/server/Dockerfile deleted file mode 100644 index fe00aa7..0000000 --- a/apps/server/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM oven/bun:1-alpine - -WORKDIR /app - -# Copy the entire project for monorepo context -COPY . . - -# Install dependencies -RUN bun install --frozen-lockfile - -WORKDIR /app/apps/server - -EXPOSE 3000 - -CMD ["bun", "run", "start"] diff --git a/apps/server/package.json b/apps/server/package.json index 4cea1e7..d0f4851 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -2,7 +2,7 @@ "name": "@alertmessagecenter/server", "version": "1.0.0", "scripts": { - "dev": "bun run --watch src/index.ts", + "dev": "bun run --env-file .env --watch src/index.ts", "start": "bun run src/index.ts", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index 004a8bb..02751a6 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -1,5 +1,6 @@ import { Hono } from 'hono'; import { cors } from 'hono/cors'; +import { serveStatic } from 'hono/bun'; import { db } from './db'; import { topics } from './db/schema'; import webhook from './webhook'; @@ -14,14 +15,15 @@ app.use('/*', cors({ credentials: true, })); -app.get('/', (c) => { - return c.text('Alert Message Center API is running!'); -}); - +// API Routes const routes = app.route('/api/auth', auth) .route('/api', api) .route('/webhook', webhook); +// Serve static files (Frontend) +app.use('/*', serveStatic({ root: './public' })); +app.get('*', serveStatic({ path: './public/index.html' })); + app.onError((err, c) => { console.error(`[Global Error] ${c.req.method} ${c.req.url}:`, err); return c.json({ error: err.message || 'Internal Server Error' }, 500); diff --git a/apps/web/.env.example b/apps/web/.env.example new file mode 100644 index 0000000..d981975 --- /dev/null +++ b/apps/web/.env.example @@ -0,0 +1,2 @@ +# Backend API URL (for proxying) +VITE_API_URL=http://localhost:3000 diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile deleted file mode 100644 index 301c8bf..0000000 --- a/apps/web/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# Build stage -FROM oven/bun:1-alpine AS builder - -WORKDIR /app - -# Copy the entire project -COPY . . - -# Install dependencies -RUN bun install --frozen-lockfile - -# Build the web app -WORKDIR /app/apps/web -RUN bun run build - -# Serve stage -FROM nginx:alpine -COPY --from=builder /app/apps/web/dist /usr/share/nginx/html -# Add a custom nginx config if needed to handle SPA routing, but for now default is okay -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] diff --git a/apps/web/package.json b/apps/web/package.json index a0dd2de..ecec8bd 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "bun run --env-file .env vite", "build": "tsc && vite build", "preview": "vite preview" }, diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index c3327c0..14e4692 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -13,11 +13,11 @@ export default defineConfig({ server: { proxy: { '/api': { - target: 'http://localhost:3000', + target: process.env.VITE_API_URL || 'http://localhost:3000', changeOrigin: true, }, '/webhook': { - target: 'http://localhost:3000', + target: process.env.VITE_API_URL || 'http://localhost:3000', changeOrigin: true, } } diff --git a/docker-compose.yml b/docker-compose.yml index 0a2801a..885d229 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ services: - server: + app: build: context: . - dockerfile: apps/server/Dockerfile + dockerfile: Dockerfile ports: - "3000:3000" environment: @@ -13,15 +13,6 @@ services: depends_on: - postgres - web: - build: - context: . - dockerfile: apps/web/Dockerfile - ports: - - "80:80" - depends_on: - - server - postgres: image: postgres:17-alpine restart: always diff --git a/package.json b/package.json index a0d4b3c..a97bfaa 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ ], "scripts": { "dev": "bun run --filter '*' dev", - "build": "bun run --filter '*' build" + "build": "bun run --filter '*' build", + "start": "bun run --filter '@alertmessagecenter/server' start" }, "devDependencies": { "bun-types": "latest"