Effect CommunityEC
Effect Community8mo ago
3 replies
Limb

HttpServerResponse.redirect

Hi, I'm trying to set up a redirect endpoint using http-server but I am running into a few issues.

I think the issue is due to the schema type set here .addSuccess(Schema.Any). I've tried a few other schema types but have had no success. Does anyone know what I should do to get this working? I've tried omitting the schema, and I've had no luck with that either.

import {
    HttpApi,
    HttpApiBuilder,
    HttpApiEndpoint,
    HttpApiGroup
} from "@effect/platform";
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";
import { Console, Effect, Layer, Schema } from "effect";
import { createServer } from "node:http";

const MyApi = HttpApi.make("Apis").add(
    HttpApiGroup.make("Some Redirect").add(
        HttpApiEndpoint.get("redirect to long url")`/:shortUrl`
            .setPath(
                Schema.Struct({
                    shortUrl: Schema.String,
                })

            )
            .addSuccess(Schema.String, { status: 302 })
            .addError(Schema.String)
    )
);

const ApiLive = HttpApiBuilder.group(MyApi, "Some Redirect", (handlers) =>
    handlers.handle("redirect to long url", (request) =>
        Effect.succeed("https://github.com/Effect-TS/effect/blob/main/packages/platform/README.md#http-server")
    )
);
Was this page helpful?