worker-time-control/proxy.js

26 lines
601 B
JavaScript
Raw Permalink Normal View History

2023-11-23 12:28:15 +00:00
const express = require('express');
2023-12-07 14:23:02 +00:00
const dotenv = require('dotenv');
2023-11-23 12:28:15 +00:00
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const env = process.env;
2023-12-07 14:23:02 +00:00
dotenv.config();
if (!env.TARGET || !env.PORT) {
console.error(`[ERROR] The '.env' file is not configured`);
process.exit();
}
2023-11-23 12:28:15 +00:00
const apiProxy = createProxyMiddleware('/api', {
target: env.TARGET,
changeOrigin: true,
2023-11-23 12:28:15 +00:00
});
app.use('/api', apiProxy);
app.use('/', express.static(__dirname));
const port = env.PORT;
2023-11-23 12:28:15 +00:00
app.listen(port, () => {
console.log(`[SERVER] Running on port: ${port}`);
2023-11-23 12:28:15 +00:00
});