feat: add HTTP and WebSocket development proxy

This commit is contained in:
2026-10-31 22:11:17 +01:00
parent 51251e444a
commit adeb68cbd5
14 changed files with 397 additions and 14 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"name": "iceberg-proxy-backend",
"private": true,
"type": "module",
"scripts": { "start": "node server.js" },
"dependencies": { "express": "^5.1.0", "ws": "^8.22.0" }
}
+15
View File
@@ -0,0 +1,15 @@
import express from 'express';
import { createServer } from 'node:http';
import { WebSocketServer } from 'ws';
const app = express();
app.get('/api/hello', (_request, response) => response.json({ message: 'Hello from Express!' }));
const server = createServer(app);
const sockets = new WebSocketServer({ noServer: true });
server.on('upgrade', (request, socket, head) => {
if (new URL(request.url, 'http://backend').pathname !== '/socket') return socket.destroy();
sockets.handleUpgrade(request, socket, head, client => sockets.emit('connection', client, request));
});
sockets.on('connection', socket => socket.send('Hello from the backend WebSocket!'));
server.listen(3001, () => console.log('Backend listening on http://localhost:3001'));