From ff9b5fa90a48629a7625d3387972e781cc0dbca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20B=C3=B6rjesson=20Skrivanos?= Date: Mon, 15 Mar 2021 11:53:52 +0100 Subject: [PATCH] fix: strip public prefix correctly on the client (#1065) Co-authored-by: Isaac Hinman --- src/config/createConfig.test.ts | 6 +++--- src/config/createConfig.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config/createConfig.test.ts b/src/config/createConfig.test.ts index 956d66ef..3861de6c 100644 --- a/src/config/createConfig.test.ts +++ b/src/config/createConfig.test.ts @@ -150,8 +150,8 @@ describe('createConfig', () => { it('returns a valid config when only lng is provided', () => { const config = createConfig({ lng: 'en' } as UserConfig) - expect((config.backend as any).addPath).toMatch('/public/locales/{{lng}}/{{ns}}.missing.json') - expect((config.backend as any).loadPath).toMatch('/public/locales/{{lng}}/{{ns}}.json') + expect((config.backend as any).addPath).toMatch('/locales/{{lng}}/{{ns}}.missing.json') + expect((config.backend as any).loadPath).toMatch('/locales/{{lng}}/{{ns}}.json') expect(config.defaultLocale).toEqual('en') expect(config.defaultNS).toEqual('common') expect(config.errorStackTraceLimit).toEqual(0) @@ -175,7 +175,7 @@ describe('createConfig', () => { lng: 'en', } as UserConfig) expect((config.backend as any).hello).toEqual('world') - expect((config.backend as any).loadPath).toMatch('/public/locales/{{lng}}/{{ns}}.json') + expect((config.backend as any).loadPath).toMatch('/locales/{{lng}}/{{ns}}.json') }) }) }) diff --git a/src/config/createConfig.ts b/src/config/createConfig.ts index 739b0014..895c0c6d 100644 --- a/src/config/createConfig.ts +++ b/src/config/createConfig.ts @@ -91,8 +91,8 @@ export const createConfig = (userConfig: UserConfig): InternalConfig => { // // Remove public prefix from client site config // - if (localePath.startsWith('/public/')) { - clientLocalePath = localePath.replace(/^\/public/, '') + if (localePath.match(/^\.?\/public\//)) { + clientLocalePath = localePath.replace(/^\.?\/public/, '') } //