Effect CommunityEC
Effect Community2mo ago
4 replies
LiquiFruit

Serving API and RPC/WSS from the Same Node Server

How can I serve my API and RPC/WSS from the same host/port/node server?

// main
import { createServer } from "node:http"

import { NodeContext, NodeHttpServer } from "@effect/platform-node"
import { Effect, ManagedRuntime } from "effect"

import { runApiServer } from "./api"
import { runRpcServer } from "./rpc"

const sharedRuntime = ManagedRuntime.make(
    NodeHttpServer.layer(createServer, { port: 3001 }),
)

Effect.gen(function* () {
    const _apiFiber = sharedRuntime.runFork(runApiServer)
    const _rpcFiber = sharedRuntime.runFork(runRpcServer)

    yield* Effect.never
}).pipe(
    Effect.provide(NodeContext.layer),
    Effect.tapError(Effect.logError),
    Effect.runPromise,
)
Was this page helpful?