-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/next/src/server/request-adapter/standalone-request-adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { BaseNextRequest } from '../base-http' | ||
import type { NextUrlWithParsedQuery } from '../request-meta' | ||
import type { RequestAdapter } from './request-adapter' | ||
import type { XInvokePathRequestAdapter } from './x-invoke-path-request-adapter' | ||
import type { XMatchedPathRequestAdapter } from './x-matched-path-request-adapter' | ||
|
||
export class StandaloneRequestAdapter<ServerRequest extends BaseNextRequest> | ||
implements RequestAdapter<ServerRequest> | ||
{ | ||
constructor( | ||
private readonly xMatchedPathRequestAdapter: XMatchedPathRequestAdapter<ServerRequest>, | ||
private readonly xInvokePathRequestAdapter: XInvokePathRequestAdapter<ServerRequest> | ||
) {} | ||
|
||
public async adapt( | ||
req: ServerRequest, | ||
parsedURL: NextUrlWithParsedQuery | ||
): Promise<void> { | ||
// Today, standalone mode is used to test the x-matched-path support as | ||
// well. | ||
|
||
// FIXME: remove this fallback when the tests are updated. | ||
if ( | ||
req.headers['x-matched-path'] && | ||
typeof req.headers['x-matched-path'] === 'string' | ||
) { | ||
return this.xMatchedPathRequestAdapter.adapt(req, parsedURL) | ||
} | ||
|
||
return this.xInvokePathRequestAdapter.adapt(req, parsedURL) | ||
} | ||
} |