Effect CommunityEC
Effect Community5mo ago
5 replies
태양

Issue with Hanging Response in RPC Server Integration with HttpServer

Hey everyone! I am running into an issue where I have a hanging response when trying to integrate an rpc server from
@effect/rpc
with HttpServer. Here is a minimal reproducible example,

import { HttpRouter, HttpServer } from "@effect/platform";
import { createServer } from "node:http";
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";
import { Effect, Layer, Schema } from "effect";
import { Rpc, RpcGroup, RpcSerialization, RpcServer } from "@effect/rpc";

const Group = RpcGroup.make(
  Rpc.make('TestRpc', {
    success: Schema.String,
    error: Schema.Void,
    payload: Schema.Void,
  }),
);

const GroupHandler = Group.toLayer({
  TestRpc: () => Effect.succeed('Hello world!'),
});

const RpcApp = RpcServer.toHttpApp(Group).pipe(
  Effect.tap(() => Effect.log('Rpc reached')),
  Effect.provide(GroupHandler),
  Effect.provide(RpcSerialization.layerJson),
  Effect.scoped,
  Effect.flatten,
);

const routes = HttpRouter.empty.pipe(HttpRouter.post("/", RpcApp))

const HttpLive = HttpServer.serve(routes).pipe(
    HttpServer.withLogAddress,
    Layer.provide(NodeHttpServer.layer(createServer, { port: 3000 }))
)

NodeRuntime.runMain(Layer.launch(HttpLive))


None of my requests ever receive a response, but I do receive confirmation that "Rpc reached" is reached whenever a request is received by the server.
Was this page helpful?