34 lines
966 B
JavaScript
34 lines
966 B
JavaScript
const express = require('express');
|
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
const path = require('path');
|
|
|
|
const app = express();
|
|
const PORT = 3000;
|
|
|
|
const COUCHDB_URL = process.env.COUCHDB_URL || 'http://admin:Couchdb01@couchdb.couchdb.svc.cluster.local:5984';
|
|
|
|
// Proxy /api/couchdb → CouchDB
|
|
app.use('/api/couchdb', createProxyMiddleware({
|
|
target: COUCHDB_URL,
|
|
changeOrigin: true,
|
|
pathRewrite: { '^/api/couchdb': '' },
|
|
on: {
|
|
error: (err, req, res) => {
|
|
console.error('CouchDB proxy error:', err.message);
|
|
res.status(502).json({ error: 'CouchDB unreachable', detail: err.message });
|
|
}
|
|
}
|
|
}));
|
|
|
|
// Serve static files
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Aangifte app running on port ${PORT}`);
|
|
console.log(`CouchDB proxy → ${COUCHDB_URL}`);
|
|
});
|