feat(backend added)

This commit is contained in:
2026-06-03 23:09:21 -06:00
parent 893b64737d
commit 43639e4de7
10 changed files with 97 additions and 217 deletions
+23
View File
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1
# Stage 1: Build frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
COPY crmDashboard/package*.json ./
RUN npm install
COPY crmDashboard/ ./
RUN npm run build
# Stage 2: Bun backend
FROM oven/bun:1-alpine
WORKDIR /app
COPY backend/package.json backend/bun.lockb* ./
RUN bun install --production
COPY backend/ ./
COPY --from=frontend-builder /app/frontend/dist ./public
EXPOSE 3000
CMD ["bun", "run", "server.js"]
+9
View File
@@ -0,0 +1,9 @@
{
"name": "crm-backend",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "bun server.js"
},
"dependencies": {}
}
+49
View File
@@ -0,0 +1,49 @@
const PUBLIC_DIR = './public'
const PORT = process.env.PORT ? Number(process.env.PORT) : 3000
function getContentType(path) {
if (path.endsWith('.html')) return 'text/html'
if (path.endsWith('.js')) return 'application/javascript'
if (path.endsWith('.css')) return 'text/css'
if (path.endsWith('.json')) return 'application/json'
if (path.endsWith('.png')) return 'image/png'
if (path.endsWith('.jpg') || path.endsWith('.jpeg')) return 'image/jpeg'
if (path.endsWith('.svg')) return 'image/svg+xml'
if (path.endsWith('.woff2')) return 'font/woff2'
if (path.endsWith('.woff')) return 'font/woff'
if (path.endsWith('.ttf')) return 'font/ttf'
return 'application/octet-stream'
}
Bun.serve({
port: PORT,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname === '/health') {
return new Response('OK', { status: 200 })
}
const filePath = url.pathname === '/' ? '/index.html' : url.pathname
const fullPath = `${PUBLIC_DIR}${filePath}`
const file = Bun.file(fullPath)
if (await file.exists()) {
return new Response(file, {
headers: { 'Content-Type': getContentType(filePath) },
})
}
// SPA fallback
const indexFile = Bun.file(`${PUBLIC_DIR}/index.html`)
if (await indexFile.exists()) {
return new Response(indexFile, {
headers: { 'Content-Type': 'text/html' },
})
}
return new Response('Not Found', { status: 404 })
},
})
console.log(`Server running on http://localhost:${PORT}`)