-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (34 loc) · 988 Bytes
/
server.js
File metadata and controls
41 lines (34 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require("express");
const httpProxy = require("http-proxy");
const app = express();
const port = process.env.PORT || 3000;
// Create a proxy server with http-proxy
const proxy = httpProxy.createProxyServer({
target:
"https://x7xejlw7ppim-dc118956-dcbb-4fae-b4ef-0a8390fe1256.tunnel.runloop.ai",
changeOrigin: true,
ws: true, // Enable WebSocket proxying
//forward: true,
//prependPath: true,
//toProxy: true,
});
proxy.on("error", (err, req, res) => {
console.error("Proxy error:", err);
res.status(500).send("Error in proxy operation");
});
// Proxy all requests
app.use((req, res) => {
proxy.web(req, res);
});
// Optionally handle WebSocket requests
app.on("upgrade", (req, socket, head) => {
proxy.ws(req, socket, head);
});
// Health check route
app.get("/health", (req, res) => {
res.send("Server is healthy");
});
// Start the server
app.listen(port, () => {
console.log(`Proxy server listening on http://localhost:${port}`);
});