middleware
middleware copied to clipboard
[Trpc Server + Cors] The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, *', but only one is allowed
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
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);
have you solved this issue , getting the same issue
Can you provide a minimal project to reproduce it?