Skip to content

Commit 6551337

Browse files
committed
Bugfixes
1 parent 48af910 commit 6551337

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ import { LanguageRouter } from "lup-language";
9595
9696
// Settings
9797
const lupLang = LanguageRouter({
98-
defaultLang: 'en',
98+
defaultLanguage: 'en',
9999
});
100100
101101
export function middleware(request: NextRequest): NextResponse {
102-
102+
103103
// Redirect to correct language
104104
const langInfo = lupLang.nextJsMiddlewareHandler(request);
105105
if(langInfo.redirect || langInfo.cookie){
106106
const langResponse = langInfo.redirect ? NextResponse.redirect(langInfo.redirect, { status: langInfo.redirectResponseCode }) : NextResponse.next();
107107
if(langInfo.cookie){
108-
langResponse.cookies.set(langInfo.name, langInfo.cookie.value, langInfo.cookie.options);
108+
langResponse.cookies.set(langInfo.cookie.name, langInfo.cookie.value, langInfo.cookie.options);
109109
}
110110
return langResponse;
111111
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lup-language",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Node express middleware for detecting requested language",
55
"files": [
66
"lib/**/*"

src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const DEFAULTS: {
108108

109109
type NextRequest = Request & {
110110
get cookies(): {
111-
get(name: string): { value: string };
111+
get(name: string): { value: string } | undefined;
112112
},
113113
};
114114

@@ -124,9 +124,11 @@ type LanguageNextResponse = {
124124
cookie?: {
125125
name: string,
126126
value: string,
127-
expire: number,
128-
domain?: string,
129-
path?: string,
127+
options: {
128+
expire: number,
129+
domain?: string,
130+
path?: string,
131+
},
130132
},
131133

132134
/** Language code that was detected. */
@@ -717,9 +719,11 @@ export const LanguageRouter = (
717719
response.cookie = {
718720
name: cookieName,
719721
value: lang,
720-
expire: cookieExpire,
721-
domain: cookieDomain ? cookieDomain : undefined,
722-
path: cookiePath ? cookiePath : undefined,
722+
options: {
723+
expire: cookieExpire,
724+
domain: cookieDomain ? cookieDomain : undefined,
725+
path: cookiePath ? cookiePath : undefined,
726+
}
723727
};
724728
}
725729

0 commit comments

Comments
 (0)