-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Handle routing by calling Next.js code #3446
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
8 Ignored Deployments
|
Benchmark for 3e5a870
Click to view full benchmark
|
|
77f9066
to
16eb958
Compare
Benchmark for e0b2b1f
Click to view full benchmark
|
Benchmark for b4413a0
Click to view full benchmark
|
6acdbfa
to
5182d57
Compare
Benchmark for a97c72c
Click to view full benchmark
|
Benchmark for 60003ab
Click to view full benchmark
|
dc3fe1c
to
62740b4
Compare
Instead, redirects will be handled via streaming middleware path
@@ -17,6 +17,7 @@ mime = "0.3.16" | |||
once_cell = "1.13.0" | |||
qstring = "0.7.2" | |||
regex = "1.6.0" | |||
reqwest = { workspace = true, features = ["stream"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in a follow up. This was part of the initial work where we would make an actual HTTP request to a router server spun up by Next.js during init.
|
||
const [_, response] = await Promise.all([ | ||
resolveRoute(serverRequest, serverResponse), | ||
handleClientResponse(ipc, clientResponsePromise), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's cleaning to pass only the clientResponse to the method?
handleClientResponse(ipc, clientResponsePromise), | |
async () => handleClientResponse(ipc, await clientResponsePromise), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored.
_ipc: Ipc<RouterRequest, IpcOutgoingMessage>, | ||
clientResponsePromise: Promise<IncomingMessage> | ||
): Promise<MessageData | void> { | ||
const clientResponse = await clientResponsePromise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks a bit weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored.
This completes a few review requests from #3446.
This completes a few review requests from #3446.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review requests addressed in #3501
@@ -17,6 +17,7 @@ mime = "0.3.16" | |||
once_cell = "1.13.0" | |||
qstring = "0.7.2" | |||
regex = "1.6.0" | |||
reqwest = { workspace = true, features = ["stream"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in a follow up. This was part of the initial work where we would make an actual HTTP request to a router server spun up by Next.js during init.
_ipc: Ipc<RouterRequest, IpcOutgoingMessage>, | ||
clientResponsePromise: Promise<IncomingMessage> | ||
): Promise<MessageData | void> { | ||
const clientResponse = await clientResponsePromise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored.
|
||
const [_, response] = await Promise.all([ | ||
resolveRoute(serverRequest, serverResponse), | ||
handleClientResponse(ipc, clientResponsePromise), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored.
Benchmark for 096307e
Click to view full benchmark
|
**Note**: This requires #45314, otherwise the following error is shown, but does not block builds: ``` error - [build] examples/create-app Error evaluating Node.js code TypeError: makeResolver is not a function at getResolveRoute (path/to/next.js/examples/create-app/.next/build/chunks/router.js:21:18) at async Module.route (path/to/next.js/examples/create-app/.next/build/chunks/router.js:24:36) at async Module.run (path/to/next.js/examples/create-app/.next/build/chunks/[turbopack-node]_ipc_evaluate.ts.js:19:39) ``` ### Features - vercel/turborepo#3446 - vercel/turborepo#3396 - vercel/turborepo#3499 ### Bug fixes - vercel/turborepo#3433 ### Misc - vercel/turborepo#3479
This completes a few review requests from #3446.
This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to: ```typescript type MakeResolver = (config: NextConfig) => Resolver; type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void; import { makeResolver } from "next/dist/..."; const resolver = makeResolver(nextConfig as object); // Later, once we have a request we'd like to route: // We don't care what the promise resolved to, we just want it to settle. await resolver(req, res); ``` The resolver can do 1 of 3 things with this: 1. ~~Return a redirect response~~ Removed 2. Return a rewrite response 3. Stream a middleware response > ~~1. Return a redirect response~~ <details> First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, statusCode: u16, headers: Record<string, string> isRedirect: true } ``` The Rust server will then respond with a redirect using to the appropriate location. </details> > 2. Return a rewrite response First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, headers: Record<string, string> } ``` The Rust server will use this updated URL to request content from our handlers. > 3. Stream a middleware response Ensure `x-nextjs-route-result` header **is not present** on the response. All headers will be sent back, and the body will be streamed back to the browser. - - - TODO: - ~~Do `headers` actually matter to a `redirect`~~ Yes? - ~~Does `statusCode` actually matter to a `rewrite`?~~ No - ~~We can't handle streaming body responses yet.~~ Mocked by buffering. Fixes WEB-228 Co-authored-by: JJ Kasper <jj@jjsweb.site>
This completes a few review requests from vercel/turborepo#3446.
This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to: ```typescript type MakeResolver = (config: NextConfig) => Resolver; type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void; import { makeResolver } from "next/dist/..."; const resolver = makeResolver(nextConfig as object); // Later, once we have a request we'd like to route: // We don't care what the promise resolved to, we just want it to settle. await resolver(req, res); ``` The resolver can do 1 of 3 things with this: 1. ~~Return a redirect response~~ Removed 2. Return a rewrite response 3. Stream a middleware response > ~~1. Return a redirect response~~ <details> First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, statusCode: u16, headers: Record<string, string> isRedirect: true } ``` The Rust server will then respond with a redirect using to the appropriate location. </details> > 2. Return a rewrite response First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, headers: Record<string, string> } ``` The Rust server will use this updated URL to request content from our handlers. > 3. Stream a middleware response Ensure `x-nextjs-route-result` header **is not present** on the response. All headers will be sent back, and the body will be streamed back to the browser. - - - TODO: - ~~Do `headers` actually matter to a `redirect`~~ Yes? - ~~Does `statusCode` actually matter to a `rewrite`?~~ No - ~~We can't handle streaming body responses yet.~~ Mocked by buffering. Fixes WEB-228 Co-authored-by: JJ Kasper <jj@jjsweb.site>
This completes a few review requests from vercel/turborepo#3446.
This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to: ```typescript type MakeResolver = (config: NextConfig) => Resolver; type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void; import { makeResolver } from "next/dist/..."; const resolver = makeResolver(nextConfig as object); // Later, once we have a request we'd like to route: // We don't care what the promise resolved to, we just want it to settle. await resolver(req, res); ``` The resolver can do 1 of 3 things with this: 1. ~~Return a redirect response~~ Removed 2. Return a rewrite response 3. Stream a middleware response > ~~1. Return a redirect response~~ <details> First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, statusCode: u16, headers: Record<string, string> isRedirect: true } ``` The Rust server will then respond with a redirect using to the appropriate location. </details> > 2. Return a rewrite response First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, headers: Record<string, string> } ``` The Rust server will use this updated URL to request content from our handlers. > 3. Stream a middleware response Ensure `x-nextjs-route-result` header **is not present** on the response. All headers will be sent back, and the body will be streamed back to the browser. - - - TODO: - ~~Do `headers` actually matter to a `redirect`~~ Yes? - ~~Does `statusCode` actually matter to a `rewrite`?~~ No - ~~We can't handle streaming body responses yet.~~ Mocked by buffering. Fixes WEB-228 Co-authored-by: JJ Kasper <jj@jjsweb.site>
This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to: ```typescript type MakeResolver = (config: NextConfig) => Resolver; type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void; import { makeResolver } from "next/dist/..."; const resolver = makeResolver(nextConfig as object); // Later, once we have a request we'd like to route: // We don't care what the promise resolved to, we just want it to settle. await resolver(req, res); ``` The resolver can do 1 of 3 things with this: 1. ~~Return a redirect response~~ Removed 2. Return a rewrite response 3. Stream a middleware response > ~~1. Return a redirect response~~ <details> First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, statusCode: u16, headers: Record<string, string> isRedirect: true } ``` The Rust server will then respond with a redirect using to the appropriate location. </details> > 2. Return a rewrite response First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, headers: Record<string, string> } ``` The Rust server will use this updated URL to request content from our handlers. > 3. Stream a middleware response Ensure `x-nextjs-route-result` header **is not present** on the response. All headers will be sent back, and the body will be streamed back to the browser. - - - TODO: - ~~Do `headers` actually matter to a `redirect`~~ Yes? - ~~Does `statusCode` actually matter to a `rewrite`?~~ No - ~~We can't handle streaming body responses yet.~~ Mocked by buffering. Fixes WEB-228 Co-authored-by: JJ Kasper <jj@jjsweb.site>
This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to: ```typescript type MakeResolver = (config: NextConfig) => Resolver; type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void; import { makeResolver } from "next/dist/..."; const resolver = makeResolver(nextConfig as object); // Later, once we have a request we'd like to route: // We don't care what the promise resolved to, we just want it to settle. await resolver(req, res); ``` The resolver can do 1 of 3 things with this: 1. ~~Return a redirect response~~ Removed 2. Return a rewrite response 3. Stream a middleware response > ~~1. Return a redirect response~~ <details> First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, statusCode: u16, headers: Record<string, string> isRedirect: true } ``` The Rust server will then respond with a redirect using to the appropriate location. </details> > 2. Return a rewrite response First, ensure a `x-nextjs-route-result: 1` header is present on the response. Then return a JSON encoded body: ```typescript { url: string, headers: Record<string, string> } ``` The Rust server will use this updated URL to request content from our handlers. > 3. Stream a middleware response Ensure `x-nextjs-route-result` header **is not present** on the response. All headers will be sent back, and the body will be streamed back to the browser. - - - TODO: - ~~Do `headers` actually matter to a `redirect`~~ Yes? - ~~Does `statusCode` actually matter to a `rewrite`?~~ No - ~~We can't handle streaming body responses yet.~~ Mocked by buffering. Fixes WEB-228 Co-authored-by: JJ Kasper <jj@jjsweb.site>
This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to:
The resolver can do 1 of 3 things with this:
Return a redirect responseRemovedFirst, ensure a
x-nextjs-route-result: 1
header is present on the response. Then return a JSON encoded body:The Rust server will then respond with a redirect using to the appropriate location.
First, ensure a
x-nextjs-route-result: 1
header is present on the response. Then return a JSON encoded body:The Rust server will use this updated URL to request content from our handlers.
Ensure
x-nextjs-route-result
header is not present on the response. All headers will be sent back, and the body will be streamed back to the browser.TODO:
DoYes?headers
actually matter to aredirect
DoesNostatusCode
actually matter to arewrite
?We can't handle streaming body responses yet.Mocked by buffering.Fixes WEB-228