mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
30 lines
904 B
JavaScript
30 lines
904 B
JavaScript
// frontend-server.js
|
|
import dotenv from 'dotenv';
|
|
import express from 'express';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
|
|
dotenv.config();
|
|
|
|
const frontendApp = express();
|
|
const backEndPort = parseInt(process.env.BACKEND_PORT || 11966, 10);
|
|
const frontEndPort = parseInt(process.env.FRONTEND_PORT || 18966, 10);
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
// API Proxy to backend server
|
|
frontendApp.use('/api', createProxyMiddleware({
|
|
target: `http://localhost:${backEndPort}/api`,
|
|
changeOrigin: true
|
|
}));
|
|
|
|
// Set static file directory
|
|
frontendApp.use(express.static(path.join(__dirname, './dist')));
|
|
|
|
// Start static file server
|
|
frontendApp.listen(frontEndPort, () => {
|
|
console.log(`Static file server running on port http://localhost:${frontEndPort}`);
|
|
});
|