worker-time-control/proxy.js

26 lines
601 B
JavaScript

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