Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trpc Server + Cors] The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed #491

Open
TheUncharted opened this issue May 1, 2024 · 0 comments

Comments

@TheUncharted
Copy link

Hi

I tested hono with trpc inside a lambda and everything is working well except when I try to add the cors middleware.
I get this error message

Access to fetch at '' from origin 'http://localhost:3000' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

In the browser I have this

image

Here's the code

import { Hono } from "hono";
import { handle } from "hono/aws-lambda";
import { cors } from "hono/cors";

import { trpcServer } from "@hono/trpc-server";

import { appRouter } from "./trpc/trpc";

const app = new Hono();

app.use(
  cors({
    
    // Only frontend is allowed
    origin: ["http://localhost:3000"],
  })
);

app.use(
  "/trpc/*",
  trpcServer({
    router: appRouter,
  })
);

export const handler = handle(app);
@TheUncharted TheUncharted changed the title [Cors] The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed [Trpc Server + Cors] The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant