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();
|
2024-01-30 11:15:31 +00:00
|
|
|
const env = process.env;
|
2023-12-07 14:23:02 +00:00
|
|
|
dotenv.config();
|
2024-01-30 11:15:31 +00:00
|
|
|
|
|
|
|
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', {
|
2024-01-30 11:15:31 +00:00
|
|
|
target: env.TARGET,
|
|
|
|
changeOrigin: true,
|
2023-11-23 12:28:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.use('/api', apiProxy);
|
|
|
|
app.use('/', express.static(__dirname));
|
|
|
|
|
2024-01-30 11:15:31 +00:00
|
|
|
const port = env.PORT;
|
2023-11-23 12:28:15 +00:00
|
|
|
app.listen(port, () => {
|
2024-01-30 11:15:31 +00:00
|
|
|
console.log(`[SERVER] Running on port: ${port}`);
|
2023-11-23 12:28:15 +00:00
|
|
|
});
|