Minor Changes
- #2261
fa9663c
Thanks @tim-smart! - move Socket module to platform
Patch Changes
-
#2267
0f3d99c
Thanks @tim-smart! - propogate Socket handler errors to .run Effect -
#2269
4064ea0
Thanks @jessekelly881! - added PlatformLogger module, for writing logs to a fileIf you wanted to write logfmt logs to a file, you can do the following:
import { PlatformLogger } from "@effect/platform"; import { NodeFileSystem, NodeRuntime } from "@effect/platform-node"; import { Effect, Layer, Logger } from "effect"; const fileLogger = Logger.logfmtLogger.pipe(PlatformLogger.toFile("log.txt")); const LoggerLive = Logger.replaceScoped( Logger.defaultLogger, fileLogger, ).pipe(Layer.provide(NodeFileSystem.layer)); Effect.log("a").pipe( Effect.zipRight(Effect.log("b")), Effect.zipRight(Effect.log("c")), Effect.provide(LoggerLive), NodeRuntime.runMain, );
-
#2261
fa9663c
Thanks @tim-smart! - add websocket support to platform http serverYou can use the
Http.request.upgrade*
apis to access theSocket
for the request.Here is an example server that handles websockets on the
/ws
path:import { NodeHttpServer, NodeRuntime } from "@effect/platform-node"; import * as Http from "@effect/platform/HttpServer"; import { Console, Effect, Layer, Schedule, Stream } from "effect"; import { createServer } from "node:http"; const ServerLive = NodeHttpServer.server.layer(() => createServer(), { port: 3000, }); const HttpLive = Http.router.empty.pipe( Http.router.get( "/ws", Effect.gen(function* (_) { yield* _( Stream.fromSchedule(Schedule.spaced(1000)), Stream.map(JSON.stringify), Stream.encodeText, Stream.pipeThroughChannel(Http.request.upgradeChannel()), Stream.decodeText(), Stream.runForEach(Console.log), ); return Http.response.empty(); }), ), Http.server.serve(Http.middleware.logger), Http.server.withLogAddress, Layer.provide(ServerLive), ); NodeRuntime.runMain(Layer.launch(HttpLive));
-
Updated dependencies [
e03811e
,ac41d84
,6137533
,f373529
,1bf9f31
,e3ff789
,6137533
,507ba40
,e466afe
,465be79
,f373529
,de74eb8
,d8e6940
]:- effect@2.4.2
- @effect/schema@0.63.3