mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-19 23:21:36 +00:00
a7adc3c36b
- Removed the `index.html` file as part of the transition to a new routing system. - Updated `package.json` scripts to streamline development commands using `concurrently`. - Enhanced dependency management by adding new packages and updating existing ones in `package.json`. - Introduced a new server function for branding and session management, improving API interactions. - Refactored routing to utilize TanStack Start, ensuring better integration with the existing Dokploy architecture. - Improved static file handling and server response management in the custom Node.js server. - Updated README to reflect changes in architecture and development processes.
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
import { Readable } from "node:stream";
|
|
|
|
interface FetchHandler {
|
|
fetch: (request: Request) => Response | Promise<Response>;
|
|
}
|
|
|
|
export const createStartBridge = (handler: FetchHandler) => {
|
|
return async (req: IncomingMessage, res: ServerResponse) => {
|
|
const url = `http://${req.headers.host ?? "localhost"}${req.url ?? "/"}`;
|
|
const headers = new Headers();
|
|
for (const [key, value] of Object.entries(req.headers)) {
|
|
if (value === undefined) continue;
|
|
if (Array.isArray(value)) {
|
|
for (const item of value) headers.append(key, item);
|
|
} else {
|
|
headers.set(key, value);
|
|
}
|
|
}
|
|
const method = req.method ?? "GET";
|
|
const hasBody = method !== "GET" && method !== "HEAD";
|
|
const request = new Request(url, {
|
|
method,
|
|
headers,
|
|
...(hasBody
|
|
? {
|
|
body: Readable.toWeb(req) as unknown as ReadableStream,
|
|
duplex: "half",
|
|
}
|
|
: {}),
|
|
} as RequestInit);
|
|
|
|
const response = await handler.fetch(request);
|
|
|
|
const outHeaders: Record<string, string | string[]> = {};
|
|
response.headers.forEach((value, key) => {
|
|
if (key === "set-cookie") return;
|
|
outHeaders[key] = value;
|
|
});
|
|
const setCookies = response.headers.getSetCookie();
|
|
if (setCookies.length > 0) {
|
|
outHeaders["set-cookie"] = setCookies;
|
|
}
|
|
|
|
res.writeHead(response.status, outHeaders);
|
|
if (response.body) {
|
|
Readable.fromWeb(response.body as never).pipe(res);
|
|
} else {
|
|
res.end();
|
|
}
|
|
};
|
|
};
|