-
Do you support Next.js App Router? :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @mrzmyr I have some thoughts about how it could be useful. Actually, this plugin is quite simple so I write an ADR for explain what it could be done to support App Router without breaking change for old version. Support for Next.js 13 App RouterDate: 2023-07-15 StatusAccepted ContextWith the introduction of Next.js 13, a new feature known as App Router was introduced. This allows for the creation of custom request handlers within the In our current codebase, we have a validation framework that works with the traditional API routes ( DecisionTo support the Next.js 13 App Router, we decided to modify our validation Higher Order Function ( If the validation is for the App Router, we will use the If the validation is for a traditional API route, we will use the existing Express-style responses ( To achieve this, we introduced a new type ApiType = 'appRoute' | 'pageRoute';
type ValidationHoF = {
type: SCHEMA_TYPE;
mode?: "body" | "query" | "headers";
schema: unknown;
apiType?: ApiType;
}; Here's a snippet of the updated export function withValidations(validations: ValidationHoF[]) {
// ...
const isAppRouter = validations.some((validation) => validation.apiType === 'appRoute');
if (isAppRouter) {
// TODO: handle 404
} else {
res.status(404).end();
}
// ...
if (isAppRouter) {
// TODO: handle error
}
res.status(400).send(error);
// ...
} ConsequencesThis decision allows us to support both the new App Router feature in Next.js 13 and the traditional API routes in our validation framework. However, developers now need to be aware of the The introduction of |
Beta Was this translation helpful? Give feedback.
-
FYI - Possible solution for reference https://github.com/KolbySisk/next-route-handler-pipe |
Beta Was this translation helpful? Give feedback.
FYI - Possible solution for reference https://github.com/KolbySisk/next-route-handler-pipe