fix(proxy): use getRequestListener instead of createAdaptorServer
createAdaptorServer creates a new HTTP server on each request, which breaks Hono routing. getRequestListener gives a proper request handler for use with an existing server. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { createServer } from 'node:http';
|
import { createServer } from 'node:http';
|
||||||
import { createAdaptorServer } from '@hono/node-server';
|
import { getRequestListener } from '@hono/node-server';
|
||||||
import { MachineState, type ServiceConfig } from '@sleepguard/shared';
|
import { MachineState, type ServiceConfig } from '@sleepguard/shared';
|
||||||
import { app } from './server/app.js';
|
import { app } from './server/app.js';
|
||||||
import { proxyRequest, proxyWebSocket } from './server/proxy.js';
|
import { proxyRequest, proxyWebSocket } from './server/proxy.js';
|
||||||
@@ -15,6 +15,8 @@ function findServiceByHost(host: string | undefined): ServiceConfig | undefined
|
|||||||
return getServiceManager().findByHost(host);
|
return getServiceManager().findByHost(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleRequest = getRequestListener(app.fetch);
|
||||||
|
|
||||||
// Create the base HTTP server with Hono
|
// Create the base HTTP server with Hono
|
||||||
const server = createServer(async (req, res) => {
|
const server = createServer(async (req, res) => {
|
||||||
const service = findServiceByHost(req.headers.host);
|
const service = findServiceByHost(req.headers.host);
|
||||||
@@ -31,8 +33,7 @@ const server = createServer(async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise let Hono handle (API, dashboard, waking page)
|
// Otherwise let Hono handle (API, dashboard, waking page)
|
||||||
const honoHandler = createAdaptorServer(app);
|
handleRequest(req, res);
|
||||||
honoHandler.emit('request', req, res);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle WebSocket upgrades
|
// Handle WebSocket upgrades
|
||||||
|
|||||||
Reference in New Issue
Block a user