Add Node.js/Express API service for booking backend
- New api/ service: Express + better-sqlite3, health check at GET /api/health, POST /api/bookings stores sessions with all required fields - Dockerfile with Alpine build deps for native sqlite3 module - docker-compose.yml: api service with volume mounts for data, signed-contracts, contracts - nginx.conf: proxy /api/ to api:3001; Immich regex locations remain higher priority - .gitignore: exclude SQLite db file and signed PDFs from version control Closes #1 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const db = require('./db');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
app.use(cors({ origin: process.env.CORS_ORIGIN || '*', credentials: true }));
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
app.post('/api/bookings', (req, res) => {
|
||||
const {
|
||||
client_name, client_email, client_phone, client_sub,
|
||||
session_date, session_type, session_length, location,
|
||||
} = req.body;
|
||||
|
||||
if (!client_email || !session_date || !session_type || !session_length) {
|
||||
return res.status(400).json({ error: 'Missing required fields' });
|
||||
}
|
||||
|
||||
const result = db.prepare(`
|
||||
INSERT INTO bookings
|
||||
(client_name, client_email, client_phone, client_sub, session_date, session_type, session_length, location)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(client_name, client_email, client_phone, client_sub, session_date, session_type, session_length, location);
|
||||
|
||||
res.status(201).json({ id: result.lastInsertRowid });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => console.log(`API listening on port ${PORT}`));
|
||||
Reference in New Issue
Block a user