Adding Logger Middleware to RPC Server with CORS

How do I add logger middleware to this example I pulled from effect/rpc README? https://www.npmjs.com/package/@effect/rpc

// server.ts
import { HttpMiddleware, HttpRouter } from '@effect/platform';
import { BunHttpServer, BunRuntime } from '@effect/platform-bun';
import { RpcSerialization, RpcServer } from '@effect/rpc';
import { Layer } from 'effect';
import { UsersLive } from './handlers.js';
import { UserRpcs } from './request.js';

console.log('Starting RPC server');
// Create the RPC server layer
const RpcLayer = RpcServer.layer(UserRpcs).pipe(Layer.provide(UsersLive));

console.log('RPC server layer created');

// Choose the protocol and serialization format
const HttpProtocol = RpcServer.layerProtocolHttp({
  path: '/rpc',
}).pipe(Layer.provide(RpcSerialization.layerJson));

console.log('HTTP protocol layer created');

// Create the main server layer with CORS and logging
const Main = HttpRouter.Default.serve(HttpMiddleware.cors()).pipe(
  Layer.provide(RpcLayer),
  Layer.provide(HttpProtocol),
  Layer.provide(BunHttpServer.layer({ port: process.env.PORT ? parseInt(process.env.PORT) : 3001 })),
);

console.log('Main layer created');

BunRuntime.runMain(Layer.launch(Main));

console.log('RPC server started');


Previously I was able to put it inside HttpRouter.Default.server(HttpMiddleware.logger).pipe(

but I need CORS as well, and I can't figure out the syntax for providing both at the same time
Was this page helpful?