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

Support basePath with edge runtime for Custom App Routes #52910

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/next/src/server/web/edge-route-module-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import type { RouteModule } from '../future/route-modules/route-module'
import type { NextRequest } from './spec-extension/request'

import './globals'

import { adapter, type AdapterOptions } from './adapter'
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 { 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'>>

Expand Down Expand Up @@ -64,7 +65,14 @@ export class EdgeRouteModuleWrapper {
private async handler(request: NextRequest): Promise<Response> {
// Get the pathname for the matcher. Pathnames should not have trailing
// 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.
const match = this.matcher.match(pathname)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
process.env.BASE_PATH = '/docs'
require('./app-custom-routes.test')
Loading