Skip to content

Commit 91ba386

Browse files
committed
Bugfix root detection
1 parent 3dff684 commit 91ba386

5 files changed

Lines changed: 213 additions & 235 deletions

File tree

.github/workflows/on-push.yml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,21 @@ name: On Push
22
on: [push]
33
jobs:
44
build:
5-
name: Building
5+
name: Build & Test
66
runs-on: Linux
77
steps:
88
- name: Checking out repository
9-
uses: actions/checkout@v3
9+
uses: actions/checkout@v4
1010
- name: "Setup Node"
11-
uses: actions/setup-node@v3
11+
uses: actions/setup-node@v4
1212
with:
13-
node-version: '16'
13+
node-version: '22'
1414
cache: 'npm'
1515
- name: Installing
16-
run: npm install -save --save-dev
16+
run: npm install
1717
- name: Building
1818
run: npm run build
19-
- name: Done
20-
run: exit 0
21-
22-
testing:
23-
name: Testing
24-
needs: build
25-
runs-on: Linux
26-
steps:
27-
- name: "Setup Node"
28-
uses: actions/setup-node@v3
29-
with:
30-
node-version: '16'
31-
cache: 'npm'
32-
- name: Installing
33-
run: npm install -save --save-dev
34-
- name: Running linter
19+
- name: Linting
3520
run: npm run lint
36-
- name: Running tests
37-
run: npm run test
38-
- name: Done
39-
run: exit 0
21+
- name: Testing
22+
run: npm run test

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![GitHub package.json version](https://img.shields.io/github/package-json/v/LupCode/node-lup-language)
22
![npm bundle size](https://img.shields.io/bundlephobia/min/lup-language)
3-
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/LupCode/node-lup-language/On%20Push)
3+
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/LupCode/node-lup-language/on-push.yml?branch=main)
44
![NPM](https://img.shields.io/npm/l/lup-language)
55

66
# lup-language
@@ -128,24 +128,27 @@ import { NextResponse } from "next/server";
128128
import type { NextRequest } from "next/server";
129129
import { LanguageRouter } from "lup-language";
130130

131+
export const runtime = 'nodejs'; // only works with NodeJS runtime
132+
131133
// Settings
132134
const lupLang = LanguageRouter({
133135
defaultLanguage: 'en',
134136
});
135137

136-
export function middleware(request: NextRequest): NextResponse {
138+
export function middleware(req: NextRequest): NextResponse {
137139

138140
// Redirect to correct language
139-
const langInfo = lupLang.nextJsMiddlewareHandler(request);
141+
const langInfo = lupLang.nextJsMiddlewareHandler(req);
140142
if(langInfo.redirect || langInfo.cookie){
141-
const langResponse = langInfo.redirect ? NextResponse.redirect(langInfo.redirect, { status: langInfo.redirectResponseCode }) : NextResponse.next();
143+
req.nextUrl.pathname = langInfo.redirect ? langInfo.redirect : req.nextUrl.pathname;
144+
const res = langInfo.redirect ? NextResponse.redirect(langInfo.redirect, { status: langInfo.redirectResponseCode }) : NextResponse.next();
142145
if(langInfo.cookie){
143-
langResponse.cookies.set(langInfo.cookie.name, langInfo.cookie.value, langInfo.cookie.options);
146+
res.cookies.set(langInfo.cookie.name, langInfo.cookie.value, langInfo.cookie.options);
144147
}
145-
return langResponse;
148+
return res;
146149
}
147150

148-
151+
149152
// Other middleware logic
150153

151154
return NextResponse.next();

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.2.2",
3+
"version": "2.2.3",
44
"description": "Node express middleware for detecting requested language",
55
"files": [
66
"lib/**/*"

src/__tests__/LanguageRouter.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { ROOT } from 'lup-root';
2-
import {
3-
DEFAULTS,
4-
getLanguages,
5-
LanguageRouter,
6-
} from '../index';
2+
import { DEFAULTS, getLanguages, LanguageRouter } from '../index';
73

84
const TRANSLATIONS_DIR = ROOT + '/src/__tests__/translations';
95

106
var handle: Function | any;
117
var locales: string[];
128
beforeAll(async () => {
13-
149
DEFAULTS.REQUEST_ADD_TRANSLATIONS_ATTRIBUTE = 'TEXT'; // by default disabled
1510

1611
handle = LanguageRouter({

0 commit comments

Comments
 (0)