You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
create a next.js app (version 14.2.4) under src add middleware.json with following contents
`import { NextResponse } from 'next/server';
import { i18nConfig } from '@/app/i18n/config';
export function middleware(request) {
const { pathname } = request.nextUrl;
// Skip middleware for static files and api routes
if (
pathname.startsWith('/_next') ||
pathname.startsWith('/api') ||
pathname.includes('/assets/') ||
pathname.includes('.')
) {
return NextResponse.next();
}
// Helper function remains the same
function getLocale(request) {
const localeCookie = request.cookies.get('NEXT_LOCALE');
if (localeCookie?.value && i18nConfig.locales.includes(localeCookie.value)) {
return localeCookie.value;
}
if (i18nConfig.locales.includes(preferredLocale)) {
return preferredLocale;
}
}
return i18nConfig.defaultLocale;
}`
deploy this to a firebase hosting site (no app connected) go to "/" path of site and see you get a link to open firebase hosting, if you add any other pages you can still navigate to those.
[REQUIRED] Steps to reproduce
see above
[REQUIRED] Expected behavior
the index.js under pages folder should be rendered.
[REQUIRED] Actual behavior
you get a link to open firebase hosting, if you add any other pages you can still navigate to those.
The text was updated successfully, but these errors were encountered:
[REQUIRED] Environment info
firebase-tools:
13.11.2
Platform:
Windows 11
[REQUIRED] Test case
create a next.js app (version 14.2.4) under src add middleware.json with following contents
`import { NextResponse } from 'next/server';
import { i18nConfig } from '@/app/i18n/config';
export function middleware(request) {
const { pathname } = request.nextUrl;
// Skip middleware for static files and api routes
if (
pathname.startsWith('/_next') ||
pathname.startsWith('/api') ||
pathname.includes('/assets/') ||
pathname.includes('.')
) {
return NextResponse.next();
}
// Handle root path redirects
if (pathname === '/') {
const locale = getLocale(request);
return NextResponse.redirect(new URL(
/${locale}
, request.url));}
// Check if the path starts with a locale
const pathnameIsMissingLocale = i18nConfig.locales.every(
locale => !pathname.startsWith(
/${locale}/
) && pathname !==/${locale}
);
if (pathnameIsMissingLocale) {
const locale = getLocale(request);
return NextResponse.redirect(
new URL(
/${locale}${pathname}
, request.url));
}
return NextResponse.next();
}
export const config = {
matcher: [
'/',
'/((?!api|_next|assets|.\..).*)'
]
};
// Helper function remains the same
function getLocale(request) {
const localeCookie = request.cookies.get('NEXT_LOCALE');
if (localeCookie?.value && i18nConfig.locales.includes(localeCookie.value)) {
return localeCookie.value;
}
const acceptLanguage = request.headers.get('accept-language');
if (acceptLanguage) {
const preferredLocale = acceptLanguage
.split(',')[0]
.split('-')[0]
.toLowerCase();
}
return i18nConfig.defaultLocale;
}`
deploy this to a firebase hosting site (no app connected) go to "/" path of site and see you get a link to open firebase hosting, if you add any other pages you can still navigate to those.
[REQUIRED] Steps to reproduce
see above
[REQUIRED] Expected behavior
the index.js under pages folder should be rendered.
[REQUIRED] Actual behavior
you get a link to open firebase hosting, if you add any other pages you can still navigate to those.
The text was updated successfully, but these errors were encountered: