Next.js Discord

Discord Forum

NextJS dynamic prefixUrl in Ky

Unanswered
Korat posted this in #help-forum
Open in Discord
Avatar
KoratOP
I am trying to create an instance of ky with a default prefix,

However, the url is a bit dynamic like .../api/{dynamicLocale}/...rest

Is there any way I can read NEXT_LOCALE from cookies and set it here ?

import ky from 'ky';

const locales: Record<string, string> = {
  en: 'en-GB',
  fr: 'fr-FR',
  nl: 'nl-NL',
};

export const api = ky.create({
  prefixUrl: 'here',
});

1 Reply

Avatar
KoratOP
Or maybe, I could just use a wrapper around ky and handle the logic inside of it like I would do with fetch.