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 App Router #49

Merged
merged 1 commit into from
Sep 13, 2023
Merged

Add support for App Router #49

merged 1 commit into from
Sep 13, 2023

Conversation

blomqma
Copy link
Owner

@blomqma blomqma commented Aug 24, 2023

Add support for App Router

This is a breaking change that adds support for
using Next REST Framework with the Next.js App Router.

The support for Pages Router is also supported, and even
both routers can be used simultaneously with the framework,
like done in the revamped example application.

There are a few fundamental changes in both the implementation
of the code and in how the framework is encouraged to be used:

Remove support for middlewares:

Next.js has it's own way of implementing middleware logic
for server-side code. By removing the optional logic for
global, route and method middlewares we ensure that any
user-defined logic in these handler's won't interfere or
encourage developers to implement their preferred logic in
a non-Next.js way.

Supporting different runtimes, like the Node.js environment and
the edge runtime are also not possible, making it wiser to leave
any additional middleware logic up to the user to implement either
directly in their route handlers, or in their global Next.js
middleware logic.

Leaving our the three-level middleware logic also simplifies the
typings, that are already very strict.

With these changes, the user can still define an optional global
error handler for catching any errors occurring in their Next REST
Framework route handlers, but defining overriding error handlers on
route or method level is no longer supported.

Remove support for HTTP TRACE:

The Next.js App Router adds it's own validation for the HTTP methods
being used, and TRACE is not supported by that. With these changes,
TRACE can no longer be used with neither App Router or Pages Router
with Next REST Framework.

Not encouraging running the generation script with next build:

The next-rest-framework binary still works in a similar way,
generating the openapi.json file in the root of the project.
Running the script that spawns a child process running a Next.js
dev server is longer encouraged to be done with next build,
as performing this in build environments can have varying success
or it may not work at all. Instead, it is recommended to still keep
the openapi.json file under source control and instead, run the
generation script as part of pre-commit hooks or before committing
changes that modify the OpenAPI spec. The openapi.json file
is still automatically updated during local development, making
this manual step redundant in most cases.

Removing support for Node.js 16:

As Node.js 16 is facing EOL, and the Next.js App Router is not
supported with Node.js 16, that Node version is longer supported.
Node 20 can be considered to be added to the CI machine matrix, but
as Vercel does not currently support Node 20, that has not yet been
done here.

Additionally, this change upgrades most dependencies to latest versions.

@vercel
Copy link

vercel bot commented Aug 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-rest-framework ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2023 11:54pm
next-rest-framework-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2023 11:54pm

@blomqma blomqma force-pushed the upgrade-dependencies branch 2 times, most recently from aff605d to 35e85ef Compare August 24, 2023 19:22
@blomqma blomqma force-pushed the upgrade-dependencies branch from 35e85ef to 7621a2b Compare August 24, 2023 19:37
@blomqma blomqma force-pushed the upgrade-dependencies branch from a261c09 to 1579a23 Compare September 11, 2023 21:52
@blomqma blomqma changed the title Upgrade dependencies Add support for App Router Sep 11, 2023
@blomqma blomqma force-pushed the upgrade-dependencies branch from 1579a23 to eba06e1 Compare September 11, 2023 21:58
@blomqma blomqma force-pushed the upgrade-dependencies branch from eba06e1 to 2b33d77 Compare September 11, 2023 22:05
@blomqma blomqma force-pushed the upgrade-dependencies branch from c0a3691 to 4dbfa07 Compare September 12, 2023 21:57
@blomqma blomqma force-pushed the upgrade-dependencies branch from 4dbfa07 to 58401ea Compare September 12, 2023 22:01
@blomqma blomqma force-pushed the upgrade-dependencies branch from 58401ea to de76816 Compare September 12, 2023 22:04
@blomqma blomqma force-pushed the upgrade-dependencies branch from de76816 to 33d53aa Compare September 12, 2023 22:06
@blomqma blomqma force-pushed the upgrade-dependencies branch from 2b17f86 to 1fe5559 Compare September 12, 2023 23:30
@blomqma blomqma force-pushed the upgrade-dependencies branch from 1fe5559 to 2a2d096 Compare September 12, 2023 23:35
@blomqma blomqma force-pushed the upgrade-dependencies branch from 2a2d096 to 236141e Compare September 12, 2023 23:39
@blomqma blomqma mentioned this pull request Sep 12, 2023
This is a breaking change that adds support for
using Next REST Framework with the Next.js App Router.

The support for Pages Router is also supported, and even
both routers can be used simultaneously with the framework,
like done in the revamped example application.

There are a few fundamental changes in both the implementation
of the code and in how the framework is encouraged to be used:

Remove support for middlewares:

Next.js has it's own way of implementing middleware logic
for server-side code. By removing the optional logic for
global, route and method middlewares we ensure that any
user-defined logic in these handler's won't interfere or
encourage developers to implement their preferred logic in
a non-Next.js way.

Supporting different runtimes, like the Node.js environment and
the edge runtime are also not possible, making it wiser to leave
any additional middleware logic up to the user to implement either
directly in their route handlers, or in their global Next.js
middleware logic.

Leaving our the three-level middleware logic also simplifies the
typings, that are already very strict.

With these changes, the user can still define an optional global
error handler for catching any errors occurring in their Next REST
Framework route handlers, but defining overriding error handlers on
route or method level is no longer supported.

Remove support for HTTP TRACE:

The Next.js App Router adds it's own validation for the HTTP methods
being used, and TRACE is not supported by that. With these changes,
TRACE can no longer be used with neither App Router or Pages Router
with Next REST Framework.

Not encouraging running the generation script with `next build`:

The `next-rest-framework` binary still works in a similar way,
generating the `openapi.json` file in the root of the project.
Running the script that spawns a child process running a Next.js
dev server is longer encouraged to be done with `next build`,
as performing this in build environments can have varying success
or it may not work at all. Instead, it is recommended to still keep
the `openapi.json` file under source control and instead, run the
generation script as part of pre-commit hooks or before committing
changes that modify the OpenAPI spec. The `openapi.json` file
is still automatically updated during local development, making
this manual step redundant in most cases.

Removing support for Node.js 16:

As Node.js 16 is facing EOL, and the Next.js App Router is not
supported with Node.js 16, that Node version is longer supported.
Node 20 can be considered to be added to the CI machine matrix, but
as Vercel does not currently support Node 20, that has not yet been
done here.

Additionally, this change upgrades most dependencies to latest versions.
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.

1 participant