Closed Maximillion195 closed 9 months ago
All /api
routes are omitted from the translations by default
The middleware only really takes effect when it’s a page route with a default locale like /en/about
redirects to /about
Are you using other middleware? Does it work when you temporarily remove the astro-i18n-aut
package? You can also try disabling the astro-i18n-aut
middleware by setting redirectDefaultLocale
to false
I am using .at()
in some of the helper functions, but they are all strings that should be defined.
If you have an example reproduction or public project on GitHub, I could take a closer look. If you do, I’ll gladly re-open this issue
I tried removing the astro-i18n-aut
package and the api route starts working again. Seems to be an issue with the baseUrl some how.
I have an example reproduction. If you deploy this to Vercel and click the Test button you should be able to see the error in the Vercel logs.
I didn't get to the root of it but it seems like the baseUrl was coming up as undefined when deployed on Vercel. I made a really hacky fix on the removeTrailingSlash
function to prevent it from erroring.
export const BASE_URL = virtualConfig.BASE_URL;
export function removeTrailingSlash(url: string) {
if (!url) return '';
return url?.at(-1) === "/" ? url.slice(0, -1) : url;
}
Thanks @Maximillion195 ! I have defaulted the BASE_URL
to /
in 0.7.0
Unfortunately, I don’t have Vercel, so if it doesn’t work with your example reproduction, please let me know and I’ll re-open the issue
Hey, was so happy to find your solution. Found it crazy that you couldn't use one template for all the translations.
Hoping you could help with an an issue i'm having when it's deployed to Vercel and I go to use an api POST endpoint that I created i'm getting a 500 error and it shows this in the logs.
Pretty new to Astro and exhausted everything I can think of trying. Let me know if you need anymore info
I set the trailing slash to what was specific in the docs
astro.config
API Endpoint - /api/upload