Unverified Commit 3e821ef1 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Support basePath with edge runtime for Custom App Routes (#52910)

Fixes a bug where the edge runtime didn't support `basePath` with Custom App Routes.

- Fixes #49661
parent 20b115e8
...@@ -4,11 +4,12 @@ import type { RouteModule } from '../future/route-modules/route-module' ...@@ -4,11 +4,12 @@ import type { RouteModule } from '../future/route-modules/route-module'
import type { NextRequest } from './spec-extension/request' import type { NextRequest } from './spec-extension/request'
import './globals' import './globals'
import { adapter, type AdapterOptions } from './adapter' import { adapter, type AdapterOptions } from './adapter'
import { IncrementalCache } from '../lib/incremental-cache' import { IncrementalCache } from '../lib/incremental-cache'
import { removeTrailingSlash } from '../../shared/lib/router/utils/remove-trailing-slash'
import { RouteMatcher } from '../future/route-matchers/route-matcher' import { RouteMatcher } from '../future/route-matchers/route-matcher'
import { removeTrailingSlash } from '../../shared/lib/router/utils/remove-trailing-slash'
import { removePathPrefix } from '../../shared/lib/router/utils/remove-path-prefix'
type WrapOptions = Partial<Pick<AdapterOptions, 'page'>> type WrapOptions = Partial<Pick<AdapterOptions, 'page'>>
...@@ -64,7 +65,14 @@ export class EdgeRouteModuleWrapper { ...@@ -64,7 +65,14 @@ export class EdgeRouteModuleWrapper {
private async handler(request: NextRequest): Promise<Response> { private async handler(request: NextRequest): Promise<Response> {
// Get the pathname for the matcher. Pathnames should not have trailing // Get the pathname for the matcher. Pathnames should not have trailing
// slashes for matching. // slashes for matching.
const pathname = removeTrailingSlash(new URL(request.url).pathname) let pathname = removeTrailingSlash(new URL(request.url).pathname)
// Get the base path and strip it from the pathname if it exists.
const { basePath } = request.nextUrl
if (basePath) {
// If the path prefix doesn't exist, then this will do nothing.
pathname = removePathPrefix(pathname, basePath)
}
// Get the match for this request. // Get the match for this request.
const match = this.matcher.match(pathname) const match = this.matcher.match(pathname)
......
process.env.BASE_PATH = '/docs'
require('./app-custom-routes.test')
/** /**
* @type {import('next').NextConfig} * @type {import('next').NextConfig}
*/ */
module.exports = { const config = {
typescript: { typescript: {
ignoreBuildErrors: true, ignoreBuildErrors: true,
}, },
} }
if (process.env.BASE_PATH) {
config.basePath = process.env.BASE_PATH
}
module.exports = config
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment