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
GRW-1510 / improvements to middleware routing #575
GRW-1510 / improvements to middleware routing #575
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apps/store/src/lib/l10n/locales.ts
Outdated
@@ -60,7 +60,7 @@ export const normalizeLocale = (locale: string | undefined): string | undefined | |||
} | |||
|
|||
// We use en-SE ISO format for settings but downcase it for routing to get nicer URLs | |||
export const routingLocale = (locale: string) => locale.toLowerCase() | |||
export const routingLocale = (locale: LocaleValues) => locale.toLowerCase() as RoutingLocale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no TS pro, but could this be or will TS complain?
export const routingLocale = (locale: LocaleValues) => locale.toLowerCase() as RoutingLocale | |
export const routingLocale = (locale: LocaleValues):RoutingLocale => locale.toLowerCase() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeahhh feels a lil dirty to be casting that type but TS complains without it since toLowerCase()
only returns a string
. So going in we have out clean and specific type. but coming out we only have a string :feelsbad:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we worker around with conversion function that return proper type
asRoutingLocale = (locale: LocaleValues): RoutingLocale => { return locale.toLowerCase() as RoutingLocale }
But only ways without assertion that I know are
- to have explicit mapping or explicit switch statement
- to check toLowerCase result agains all possible keys in RoutingLocale
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Something to think about for the future is that we might want to redirect any URL that doesn't contain a locale but let's start like this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Some nit comments
apps/store/src/components/CountrySelectorPage/CountrySelectorPage.tsx
Outdated
Show resolved
Hide resolved
apps/store/src/lib/l10n/locales.ts
Outdated
@@ -60,7 +60,7 @@ export const normalizeLocale = (locale: string | undefined): string | undefined | |||
} | |||
|
|||
// We use en-SE ISO format for settings but downcase it for routing to get nicer URLs | |||
export const routingLocale = (locale: string) => locale.toLowerCase() | |||
export const routingLocale = (locale: LocaleValues) => locale.toLowerCase() as RoutingLocale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we worker around with conversion function that return proper type
asRoutingLocale = (locale: LocaleValues): RoutingLocale => { return locale.toLowerCase() as RoutingLocale }
But only ways without assertion that I know are
- to have explicit mapping or explicit switch statement
- to check toLowerCase result agains all possible keys in RoutingLocale
Describe your changes
Add logging on the root middleware (this is for our testing now, could be removed later)
Changed the routing to use lowercase routing for pretty urls 🍒
.../sv-SE/
to.../sv-se/
Tighten up the types being used by for localisation
Justify why they are needed
Jira issue(s): GRW-1510
Checklist before requesting a review