Express-Server für Appwrite-Auth, Session, Projekt-Dashboard und Gitea-Webhook; statisches Frontend und Schema-Dokumentation für woms-database. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import express from 'express'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { config, assertServerConfig } from './config.js'
|
|
import { sessionMiddleware } from './middleware/session.js'
|
|
import authRoutes from './routes/auth.js'
|
|
import projectsRoutes from './routes/projects.js'
|
|
import featuresRoutes from './routes/features.js'
|
|
import giteaWebhookRoutes from './routes/webhook/gitea.js'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const publicDir = path.join(__dirname, '..', 'public')
|
|
|
|
assertServerConfig()
|
|
|
|
const app = express()
|
|
app.use(sessionMiddleware())
|
|
app.use(express.json({ limit: '2mb' }))
|
|
|
|
app.use('/api/auth', authRoutes)
|
|
app.use('/api/projects', projectsRoutes)
|
|
app.use('/api/features', featuresRoutes)
|
|
app.use('/webhook', giteaWebhookRoutes)
|
|
|
|
app.get('/api/health', (_req, res) => {
|
|
res.json({ ok: true, service: 'webklar-kundenbereich' })
|
|
})
|
|
|
|
app.use(express.static(publicDir))
|
|
|
|
app.get('/dashboard.html', (req, res, next) => {
|
|
const raw = req.signedCookies?.[config.cookieName]
|
|
if (!raw) {
|
|
return res.redirect('/login.html')
|
|
}
|
|
next()
|
|
})
|
|
|
|
app.get('/', (_req, res) => {
|
|
res.redirect('/login.html')
|
|
})
|
|
|
|
app.listen(config.port, () => {
|
|
console.log(`Webklar Kundenbereich läuft auf Port ${config.port}`)
|
|
})
|