Skip to content
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
3 changes: 2 additions & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-
import { denormalizePagePath } from '../shared/lib/page-path/denormalize-page-path'
import * as Log from '../build/output/log'
import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters'
import { getUtils, normalizeNextQueryParam } from './server-utils'
import { getUtils } from './server-utils'
import isError, { getProperError } from '../lib/is-error'
import {
addRequestMeta,
Expand Down Expand Up @@ -111,6 +111,7 @@ import { sendResponse } from './send-response'
import { handleInternalServerErrorResponse } from './future/route-modules/helpers/response-handlers'
import {
fromNodeOutgoingHttpHeaders,
normalizeNextQueryParam,
toNodeOutgoingHttpHeaders,
} from './web/utils'
import { CACHE_ONE_YEAR, NEXT_CACHE_TAGS_HEADER } from '../lib/constants'
Expand Down
18 changes: 0 additions & 18 deletions packages/next/src/server/server-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ export function normalizeVercelUrl(
}
}

/**
* Normalizes `nxtP` and `nxtI` query param values to remove the prefix.
* This function does not mutate the input key; it calls the provided function
* with the normalized key.
*/
export function normalizeNextQueryParam(
key: string,
onKeyNormalized: (normalizedKey: string) => void
) {
const prefixes = [NEXT_QUERY_PARAM_PREFIX, NEXT_INTERCEPTION_MARKER_PREFIX]
for (const prefix of prefixes) {
if (key !== prefix && key.startsWith(prefix)) {
const normalizedKey = key.substring(prefix.length)
onKeyNormalized(normalizedKey)
}
}
}

export function interpolateDynamicPath(
pathname: string,
params: ParsedUrlQuery,
Expand Down
3 changes: 1 addition & 2 deletions packages/next/src/server/web/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestData, FetchEventResult } from './types'
import type { RequestInit } from './spec-extension/request'
import { PageSignatureError } from './error'
import { fromNodeOutgoingHttpHeaders } from './utils'
import { fromNodeOutgoingHttpHeaders, normalizeNextQueryParam } from './utils'
import { NextFetchEvent } from './spec-extension/fetch-event'
import { NextRequest } from './spec-extension/request'
import { NextResponse } from './spec-extension/response'
Expand All @@ -18,7 +18,6 @@ import { getTracer } from '../lib/trace/tracer'
import type { TextMapGetter } from 'next/dist/compiled/@opentelemetry/api'
import { MiddlewareSpan } from '../lib/trace/constants'
import { getEdgePreviewProps } from './get-edge-preview-props'
import { normalizeNextQueryParam } from '../server-utils'

export class NextRequestHint extends NextRequest {
sourcePage: string
Expand Down
22 changes: 22 additions & 0 deletions packages/next/src/server/web/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { OutgoingHttpHeaders } from 'http'
import {
NEXT_INTERCEPTION_MARKER_PREFIX,
NEXT_QUERY_PARAM_PREFIX,
} from '../../lib/constants'

/**
* Converts a Node.js IncomingHttpHeaders object to a Headers object. Any
Expand Down Expand Up @@ -146,3 +150,21 @@ export function validateURL(url: string | URL): string {
)
}
}

/**
* Normalizes `nxtP` and `nxtI` query param values to remove the prefix.
* This function does not mutate the input key; it calls the provided function
* with the normalized key.
*/
export function normalizeNextQueryParam(
key: string,
onKeyNormalized: (normalizedKey: string) => void
) {
const prefixes = [NEXT_QUERY_PARAM_PREFIX, NEXT_INTERCEPTION_MARKER_PREFIX]
for (const prefix of prefixes) {
if (key !== prefix && key.startsWith(prefix)) {
const normalizedKey = key.substring(prefix.length)
onKeyNormalized(normalizedKey)
}
}
}
4 changes: 4 additions & 0 deletions test/e2e/app-dir/app-middleware/app-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ createNextDescribe(
}, /app-dir/)
})

it('should not include any warnings about using Node.js APIs', async () => {
expect(next.cliOutput).not.toContain('A Node.js module is loaded')
})

describe.each([
{
title: 'Serverless Functions',
Expand Down
Loading