honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
20.36k stars 583 forks source link

Dynamic Subdomain Not Detected in the Requests #3429

Open mo-hassann opened 1 month ago

mo-hassann commented 1 month ago

What is the feature you are proposing?

There is an issue with detecting dynamic subdomains when using the Hono client (hc) in Next.js application.

image when the user in the subdomain route the Hono API call goes to the main route http://localhost:3000 instead of the route with the subdomain that the user is currently in http://store1.localhost:3000.

image

All the API requests goes to this URL instead of the dynamic URL with the subdomain and that cause an issue because I use the subdomain name to fetch data based on this subdomain name.

When I change the NEXT_PUBLIC_APP_URL manually to be as the URL with the current subdomain every thing works fine.

import { AppType } from "./";
import { hc } from "hono/client";

const client = hc<AppType>(process.env.NEXT_PUBLIC_APP_URL!) // http://localhost:3000 -> http://store1.localhost:3000
yusukebe commented 1 month ago

Hi @mo-hassann

Basically, the hc is wrapping the fetch, so the behavior is based on the fetch. If you change it to fetch, will the behavior change?