-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (25 loc) · 1003 Bytes
/
server.js
File metadata and controls
31 lines (25 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const path = require('path');
// use a .env file this is in place to definen the defaults.
const ADGUARD_HOST = process.env.ADGUARD_HOST || 'http://1.2.3.4:3000';
const ADGUARD_AUTH = process.env.ADGUARD_AUTH || null; // user:pass or empty
const PORT = process.env.PORT || 3000;
const app = express();
// 1) Serve statics uit /public
app.use(express.static(path.join(__dirname, 'public')));
// 2) Fallback voor /
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
// 3) Proxy enkel /api/querylog
const proxyOpts = {
target: ADGUARD_HOST,
changeOrigin: true,
pathRewrite: { '^/api/querylog': '/control/querylog' },
...(ADGUARD_AUTH ? { auth: ADGUARD_AUTH } : {})
};
app.use('/api/querylog', createProxyMiddleware(proxyOpts));
app.listen(PORT, () => {
console.log(`Log Viewer draait op poort ${PORT}, haalt data op bij ${ADGUARD_HOST}`);
});