feat(web): port Fase 5 static file server w/ traversal protection; feat(grpc): port health stub
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "@zesdex/grpc",
|
||||
"version": "1.21.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"grpc": "bun src/main.ts",
|
||||
"build": "true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Zesdex gRPC interface package.
|
||||
* Mirrors `apps/interfaces/grpc/`.
|
||||
*/
|
||||
export { startGrpcServer, handleGrpcRequest } from "./server.ts";
|
||||
export type { GrpcState } from "./server.ts";
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bun
|
||||
/**
|
||||
* Zesdex gRPC server — standalone entry point (HTTP health stub).
|
||||
* Mirrors the `--grpc` mode of the Rust gateway.
|
||||
*/
|
||||
import { startGrpcServer } from "./index.ts";
|
||||
|
||||
const port = Number.parseInt(process.env.ZESDEX_GRPC_PORT ?? "50051", 10);
|
||||
startGrpcServer(port);
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bun
|
||||
/**
|
||||
* Zesdex gRPC interface — high-performance RPC with protobuf.
|
||||
* Mirrors `apps/interfaces/grpc/src/lib.rs`.
|
||||
*
|
||||
* For now this crate provides a minimal HTTP health-check endpoint so
|
||||
* consumers can verify the gRPC server is reachable. Full gRPC would use
|
||||
* tonic+prost (Rust) — in Bun/TS a real gRPC server would use `@grpc/grpc-js`
|
||||
* + generated protobuf types. This is intentionally a health stub.
|
||||
*/
|
||||
|
||||
/** gRPC server state (minimal for health checks). */
|
||||
export interface GrpcState {
|
||||
version: string;
|
||||
}
|
||||
|
||||
/** Build the gRPC health router. */
|
||||
export function handleGrpcRequest(_state: GrpcState, req: Request): Response {
|
||||
const url = new URL(req.url);
|
||||
if (url.pathname === "/grpc/health") {
|
||||
return new Response("gRPC server is running", {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
||||
});
|
||||
}
|
||||
return new Response("Not found", { status: 404 });
|
||||
}
|
||||
|
||||
/** Start the gRPC server (HTTP health stub). */
|
||||
export function startGrpcServer(port: number): { stop: () => void } {
|
||||
const state: GrpcState = { version: "1.21.2" };
|
||||
const server = Bun.serve({
|
||||
port,
|
||||
fetch(req) {
|
||||
return handleGrpcRequest(state, req);
|
||||
},
|
||||
});
|
||||
console.log(`zesdex-grpc listening on http://0.0.0.0:${server.port}`);
|
||||
console.log("Note: gRPC currently runs HTTP health endpoint. Add @grpc/grpc-js for full gRPC.");
|
||||
return { stop: () => server.stop(true) };
|
||||
}
|
||||
Reference in New Issue
Block a user