Skip to content
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

Locale slug is added to api and other routes outside of app dir #1157

Open
J4v4Scr1pt opened this issue Oct 11, 2023 · 0 comments
Open

Locale slug is added to api and other routes outside of app dir #1157

J4v4Scr1pt opened this issue Oct 11, 2023 · 0 comments

Comments

@J4v4Scr1pt
Copy link

What version of this package are you using?
2.6.0

What operating system, Node.js, and npm version?
pnpm: 8.8.0
node: 20.7.0
Windows 10

What happened?
I have built my application not to utilize the Internationalization (i18n) Routing rather using the queryParam from next-translate.
Everything works as expected, but I get this error and similar on the Node-server. I don't want or need the api to be prefixed with locale. Or any page for that matter.

Failed to write image to cache /en-US/api/health [Error: ENOENT: no such file or directory, mkdir '/app/.next/server/app/en-US'] {errno: -2,code: 'ENOENT',syscall: 'mkdir',path: '/app/.next/server/app/en-US'}

What did you expect to happen?
That it should not add the prefix to the URL.
To have a setting or way to opt-out of automatic adding the locale to the URL.

Are you willing to submit a pull request to fix this bug?
I would but, my knowlage on this very limited

Folder structure
image

Code
middleware:

export default async function middleware(request: NextRequest) {
	const locale = request.nextUrl.locale || i18n.defaultLocale;
	request.nextUrl.searchParams.set('lang', locale);
	request.nextUrl.href = request.nextUrl.href.replace(`/${locale}`, '');
	return NextResponse.rewrite(request.nextUrl);
}

export const config = {
	matcher: ['/((?!Login/|api|_next/static|_next/image|favicon.ico).*)', '/'],
};

i18n:

module.exports = {
	locales: ['en-US', 'da-DK', 'fi-FI', 'sv-SE', 'nb-NO', 'de-DE'],
	defaultLocale: 'en-US',
	pages: {
		'*': ['common'],
		'/(main-app)': ['home'],
		'/(main-app)/Overview': ['overview'],
	},
	logBuild: false,
	loadLocaleFrom: (lang, ns) =>
		// You can use a dynamic import, fetch, whatever. You should
		// return a Promise with the JSON file.
		// Needed because standard notation for culture is e.g. en instead of en-US
		import(`./locales/${lang}/${ns}.json`).then((m) => m.default),
};

next.config:

/** @type {import('next').NextConfig} */

const nextTranslate = require('next-translate-plugin');

const nextConfig = {
	basePath: '/next',
	output: 'standalone',
};

module.exports = nextTranslate(nextConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant