Effect CommunityEC
Effect Community2y ago
16 replies
j41n

Issue with HttpServer.response.file method in serving files

Hi. I am having problems to serve a file via the HttpServer.response.file method:
const app = HttpServer.router.empty.pipe(
  HttpServer.router.get('/', HttpServer.response.file('/home/someuser/somedir/index.html')),
  HttpServer.router.get('/api/status', getStatus),
);

The server will not return file contents, instead it returns an empty document with status 500.

Rest of the code
const HttpServerLive = Layer.mergeAll(
  NodeContext.layer,
  NodeHttpServer.etag.layer,
  NodeHttpServer.server.layerServer(createServer, {port: 3000}),
);

export const AppLive = HttpServer.server.serve(app).pipe(
  Layer.provide(HttpServerLive),
);

pipe(Layer.launch(AppLive), NodeRuntime.runMain);


Should be a layer issue i guess. But cant find any layer exported by platform-node that i can use...

I get the TS error:

Argument of type 'RunMain' is not assignable to parameter of type '(a: Effect<never, ServeError, Platform>) => void'.
  Types of parameters 'effect' and 'a' are incompatible.
    Type 'Effect<never, ServeError, Platform>' is not assignable to type 'Effect<never, ServeError, never>'.
      Type 'Platform' is not assignable to type 'never'.

pipe(Layer.launch(AppLive), NodeRuntime.runMain);
Was this page helpful?