Closed effect-bot closed 1 month ago
REPRO:
import {
HttpMiddleware,
HttpServer,
HttpServerRequest,
HttpServerResponse,
} from "@effect/platform";
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";
import { Layer, Effect } from "effect";
import { createServer } from "node:http";
const ServerLive = NodeHttpServer.layer(() => createServer(), { port: 3000 });
const HttpLive = HttpServer.serve(
Effect.gen(function* () {
const req = yield* HttpServerRequest.HttpServerRequest;
console.log(req.url);
console.log(req.originalUrl);
const searchParams = yield* HttpServerRequest.ParsedSearchParams;
console.log(searchParams);
return HttpServerResponse.text("hi");
}).pipe(HttpMiddleware.searchParamsParser, HttpMiddleware.logger)
).pipe(HttpServer.withLogAddress, Layer.provide(ServerLive));
NodeRuntime.runMain(Layer.launch(HttpLive));
[16:37:43.744] INFO (#0): Listening on http://0.0.0.0:3000
[16:37:47.884] INFO (#19) http.span.1=1ms:
TypeError: "/" cannot be parsed as a URL.
at URL (native)
at <anonymous> (/Users/ethan/src/personal/effect-playground-2/node_modules/@effect/platform/dist/esm/internal/httpMiddleware.js:111:56)
at runLoop (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/fiberRuntime.js:1100:34)
at evaluateEffect (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/fiberRuntime.js:703:27)
at start (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/fiberRuntime.js:756:14)
at <anonymous> (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/runtime.js:52:18)
at <anonymous> (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/FiberSet.js:214:19)
at handler (/Users/ethan/src/personal/effect-playground-2/node_modules/@effect/platform-node/dist/esm/internal/httpServer.js:85:19)
at emit (node:events:180:48)
at fetch (node:http:482:12)
at http.server GET
http.status: 500
http.method: GET
http.url: /
[16:38:00.391] INFO (#20) http.span.2=0ms:
TypeError: "/foo/bar?bar=baz" cannot be parsed as a URL.
at URL (native)
at <anonymous> (/Users/ethan/src/personal/effect-playground-2/node_modules/@effect/platform/dist/esm/internal/httpMiddleware.js:111:56)
at runLoop (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/fiberRuntime.js:1100:34)
at evaluateEffect (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/fiberRuntime.js:703:27)
at start (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/fiberRuntime.js:756:14)
at <anonymous> (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/internal/runtime.js:52:18)
at <anonymous> (/Users/ethan/src/personal/effect-playground-2/node_modules/effect/dist/esm/FiberSet.js:214:19)
at handler (/Users/ethan/src/personal/effect-playground-2/node_modules/@effect/platform-node/dist/esm/internal/httpServer.js:85:19)
at emit (node:events:180:48)
at fetch (node:http:482:12)
at http.server GET
http.status: 500
http.method: GET
http.url: /foo/bar?bar=baz
Summary
The user is discussing a potential issue in the Effect-TS codebase, specifically in the
httpMiddleware.ts
file. They suggest that the code should useServerRequest.searchParamsFromURL(new URL(request.originalUrl))
instead of the current implementation becauseServerRequest.url
is stripped.Additionally, the user questions the naming conventions used in the
ServerRequest
object, particularly the distinction betweenServerRequest.url
andServerRequest.originalUrl
. They express concern that deviating from the web standardRequest
'surl
property might be confusing and suggest using a different term for the parsed URL, similar to how Next.js usesNextRequest.pathname
.Key Takeaways:
ServerRequest.url
vs.ServerRequest.originalUrl
.Discord thread
https://discord.com/channels/795981131316985866/1286042509616746519