Closed elron closed 4 weeks ago
Does excluding the /api
route fix the problem? see https://inlang.com/m/dxnzrydw/paraglide-sveltekit-i18n/advanced-usage#excluding-certain-routes
This is incredibly weird, fetch
isn't supposed to be rewritten at all. exclude
shouldn't be needed. I'll look into this
Are you using the normal fetch
function or the one passed as an argument in +page.server.ts#load
?
I think I use the normal one, not svelte one. Because this runs on the browser.
Does excluding the
/api
route fix the problem? see https://inlang.com/m/dxnzrydw/paraglide-sveltekit-i18n/advanced-usage#excluding-certain-routes
I can't disable it, otherwise I will literally have two API endpoints for two different languages. Exclude is needed
I didn't notice before but I thought this is important to mention that this fetch function runs twice. Maybe this will beneficial: https://www.loom.com/share/1087f09d69544119a379c9832ceb8e94
Thanks for the video, that was really helpful
I think I know what's going on. fetch()
itself isn't rewritten. Instead what's happening is that it's making requests to /api/*
, which are then redirected to /[lang]/api/*
. That's the second request you're seeing.
If you exclude /api
it should work:
export const i18n = createI18n(runtime, {
exclude: ["/api", /^\/api\/.*/]
})
Exclude in this case means "please don't redirect requests that start with /api" so you won't get multiple endpoints for different langauges.
That fixed it!
Maybe add to the documentation?
I will!
Thanks for the support
when I run this in my
+page.svelte
const res = await fetch(`/api/reveal-pro/${confettiRef.id}`, { method: 'POST' });
it fetches from
/he/api/...
(with the language tag:/he
or/en
, when it should be fetch without language taglocalhost:1234/api
even that I have
/api
in the exclude:How do I bypass that problem?