| 50 | } |
| 51 | |
| 52 | export async function createSpaServer() { |
| 53 | const app = express() |
| 54 | |
| 55 | app.use( |
| 56 | '/api', |
| 57 | createProxyMiddleware({ |
| 58 | target: `http://localhost:${startPort}/api`, // Replace with your target server's URL |
| 59 | changeOrigin: false, // Needed for virtual hosted sites, |
| 60 | }), |
| 61 | ) |
| 62 | |
| 63 | app.use( |
| 64 | '/_serverFn', |
| 65 | createProxyMiddleware({ |
| 66 | target: `http://localhost:${startPort}/_serverFn`, // Replace with your target server's URL |
| 67 | changeOrigin: false, // Needed for virtual hosted sites, |
| 68 | }), |
| 69 | ) |
| 70 | |
| 71 | app.use(express.static(distClientDir)) |
| 72 | |
| 73 | app.get('/{*splat}', (req, res) => { |
| 74 | res.sendFile(path.resolve(distClientDir, 'index.html')) |
| 75 | }) |
| 76 | |
| 77 | return { app } |
| 78 | } |
| 79 | |
| 80 | if (isSpaMode) { |
| 81 | createSpaServer().then(async ({ app }) => |