You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There ought to be a way to add behavior that applies to all routes or all routes within a directory. This will be useful for use cases like handling authentication globally.
I'm thinking about adding an extension point via an _.intercept.ts file.
The file would export a function that looks like this:
The respondTo function is the operation function (GET, POST, etc) in the file corresponding to the path. The idea here is we can modify the request before it's passed to that function and modify the response after it's returned from the function. We can also skip the function altogether and return a different response.
It's basically a middleware but I hesitate to call it that because relating it to express / koa middleware may cause confusion.
Type safety may be a bit involved here. That INTERCEPT type will have to be overloaded with a type for each combination of path and method. The argument and return type of respondTo can be imported from files that specify path types.
The text was updated successfully, but these errors were encountered:
There ought to be a way to add behavior that applies to all routes or all routes within a directory. This will be useful for use cases like handling authentication globally.
I'm thinking about adding an extension point via an _.intercept.ts file.
The file would export a function that looks like this:
The respondTo function is the operation function (GET, POST, etc) in the file corresponding to the path. The idea here is we can modify the request before it's passed to that function and modify the response after it's returned from the function. We can also skip the function altogether and return a different response.
It's basically a middleware but I hesitate to call it that because relating it to express / koa middleware may cause confusion.
Type safety may be a bit involved here. That INTERCEPT type will have to be overloaded with a type for each combination of path and method. The argument and return type of
respondTo
can be imported from files that specify path types.The text was updated successfully, but these errors were encountered: