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

add support for edge #82

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

add support for edge #82

wants to merge 3 commits into from

Conversation

itelo
Copy link
Contributor

@itelo itelo commented Jul 13, 2023

This PR contains a LOT of stuff, and will probably be split into some PRs

  1. edge only supports web native API, so some things we do in the generated scripts are not allowed, and we should either move them to a new package (nextlove-generate) or improve the build to not bundle everything in one file.
  2. move the nextjs-wrappers-middleware and nextjs-exception-middleware to nextlove
  3. nsm needs to support the new folder structure (/app), unable to test until it.
  4. we need to check the issue with nextjs redirects (in nextjs config file)

After that, we are good to go.

The final result is:

image
image

Note that: responseEdge, edgeBody, and edgeQuery are variable names just to make it work, I'll appreciate it with you have better names.

source: "/:path*",
destination: "/api/:path*",
},
// REVIEW: I was not able to make the redirect work
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not make the redirect work, maybe there is some issue with having /app and /pages simultaneously.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea it's ok to not have /pages and /app simultaneously 👍 we should support app directory but that's non-critical for now

...((globalMiddlewares || []) as []),
auth_middleware,
...((spec.middlewares || []) as []),
// we don't need the withMethods middleware in Edge
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the withMethods middleware in Edge

addOkStatus
}: {
addIf?: (req: NextloveRequest) => boolean
addOkStatus?: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to put the addOkStatus in the exception middleware, so I put it here and it's working fine

@itelo itelo changed the title edge add support for edge Jul 13, 2023
@codetheweb
Copy link
Contributor

nsm needs to support the new folder structure (/app), unable to test until it.

I think we can opt-in specific routes without using /app: https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#segment-runtime-option

Comment on lines +13 to +14
export const GET = withRouteSpecEdge(route_spec)((req) => {
return req.responseEdge.status(200).json({ return: true })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mirroring the interface of non-edge with

Suggested change
export const GET = withRouteSpecEdge(route_spec)((req) => {
return req.responseEdge.status(200).json({ return: true })
export const GET = withRouteSpecEdge(route_spec)((req, res) => {
return res.status(200).json({ return: true })

would be a bit easier to use (since responseEdge is already an artificial construct anyways)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just created a PR to solve this, great idea.

#85

this will also make it easier to remove the duplicated code

#86

// {
// source: "/:path*",
// destination: "/api/:path*",
// },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itelo I think it would be a lot better if we created an example-edge-todo-app instead of modifying the existing one, we can merge them later, but for now changing this file is too difficult because it's not clear if you're introducing a regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants