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

Fix edge rewrite handling #40115

Merged
merged 3 commits into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -1578,6 +1578,18 @@ export default abstract class Server<ServerOptions extends Options = Options> {
if (result !== false) return result
}
}

// currently edge functions aren't receiving the x-matched-path
// header so we need to fallback to matching the current page
// when we weren't able to match via dynamic route to handle
// the rewrite case
// @ts-expect-error extended in child class web-server
if (this.serverOptions.webServerConfig) {
// @ts-expect-error extended in child class web-server
ctx.pathname = this.serverOptions.webServerConfig.page
const result = await this.renderPageComponent(ctx, bubbleNoFallback)
if (result !== false) return result
}
} catch (error) {
const err = getProperError(error)

Expand Down
2 changes: 2 additions & 0 deletions packages/next/server/web-server.ts
Expand Up @@ -328,6 +328,8 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
query: NextParsedUrlQuery,
renderOpts: RenderOpts
): Promise<RenderResult | null> {
console.log('web-server renderHTML', { url: req.url, pathname })
ijjk marked this conversation as resolved.
Show resolved Hide resolved

const { pagesRenderToHTML, appRenderToHTML } =
this.serverOptions.webServerConfig
const curRenderToHTML = pagesRenderToHTML || appRenderToHTML
Expand Down
1 change: 1 addition & 0 deletions test/e2e/switchable-runtime/index.test.ts
Expand Up @@ -16,6 +16,7 @@ function splitLines(text) {

async function testRoute(appPort, url, { isStatic, isEdge }) {
const html1 = await renderViaHTTP(appPort, url)
console.error({ html1 })
ijjk marked this conversation as resolved.
Show resolved Hide resolved
const renderedAt1 = +html1.match(/Time: (\d+)/)[1]
expect(html1).toContain(`Runtime: ${isEdge ? 'Edge' : 'Node.js'}`)

Expand Down