feat(backend): Express-Server liefert statisch + /api/health

This commit is contained in:
Kenearos 2026-07-07 15:40:06 +02:00
parent 4eed9d0c4c
commit 3b0632c4b9
4 changed files with 58 additions and 9 deletions

View file

@ -1,14 +1,16 @@
FROM node:20-alpine
FROM node:20-slim
# Install simple static file server
RUN npm install -g serve
# Create app directory
WORKDIR /app
# Copy all files
# Erst Manifeste kopieren → Layer-Cache für npm install
COPY package*.json ./
RUN npm install --omit=dev
# Rest der App
COPY . .
# Start server on the port defined by Railway ($PORT)
# If $PORT is not set, default to 3000
CMD serve -s . -l tcp://0.0.0.0:${PORT:-3000}
ENV PORT=3000
ENV DATA_DIR=/data
EXPOSE 3000
CMD ["node", "server/index.js"]

14
package.json Normal file
View file

@ -0,0 +1,14 @@
{
"name": "dienstplan-pro",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"scripts": {
"start": "node server/index.js",
"test": "node --test"
},
"dependencies": {
"better-sqlite3": "^11.3.0",
"express": "^4.21.0"
}
}

17
server/index.js Normal file
View file

@ -0,0 +1,17 @@
const path = require('path');
const express = require('express');
const app = express();
app.use(express.json({ limit: '5mb' }));
app.get('/api/health', (req, res) => res.json({ status: 'ok' }));
// Statisches Frontend (Repo-Root). Dotfiles werden per Default nicht ausgeliefert.
app.use(express.static(path.join(__dirname, '..')));
if (require.main === module) {
const PORT = process.env.PORT || 3000;
app.listen(PORT, '0.0.0.0', () => console.log(`Dienstplan-Pro auf :${PORT}`));
}
module.exports = app;

16
server/index.test.js Normal file
View file

@ -0,0 +1,16 @@
const { test } = require('node:test');
const assert = require('node:assert');
const app = require('./index');
test('GET /api/health liefert ok', async () => {
const server = app.listen(0);
const { port } = server.address();
try {
const res = await fetch(`http://127.0.0.1:${port}/api/health`);
assert.strictEqual(res.status, 200);
const body = await res.json();
assert.strictEqual(body.status, 'ok');
} finally {
server.close();
}
});