-
Notifications
You must be signed in to change notification settings - Fork 80
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 Route for Next App Directory #156
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Awesome thank you for this PR and getting it added! I'm a little hesitant to duplicating the code because we have a lot of tests that cover various uploads and we'd need to also duplicate those. I agree that an abstraction it the right approach, do you want to take a shot at doing that? Happy to answer any questions or help! |
I've reduced most of the code duplication, extracted it out into |
Oh awesome, it's looking good! Thanks for doing this, I know that part of the code can be narly with all the config/options everywhere! 👍 Yup I think we should support the existing API so people upgrading don't have to touch their existing pages/api/s3-upload.ts files. Looks like your code will support that though. Let me know when you want me to take a look and test it. I can take care of adding the automated tests... since I want to create a new Next 13 test app and use it there. Thanks again for adding this, really appreciate it! |
Everything looks ready for review, let me know if you want me to write/update any tests or docs. |
Happy to help out testing as well - we have an app being ported to app-router at the mo. |
@devandnow I would love some more testing on this! Also just cleaned up the error responses, not sure if I like the |
Agree - consolling on the api route will be super helpful whilst everyone settles into the app-router methods. I'll setup a sandbox and will report back :) |
This all works for me - I tested on a /pages and this new method and didn't notice any major differences so I 'think' all good to go |
@ryanto be great if you have some time to approve |
@martinmiglio cheers for that, I need it as well 👍 |
Ok next-s3-upload should now be usable with the app router in version Here's all you need: // app/api/s3-upload/route.js
export { POST } from "next-s3-upload/route"; Huge thanks to @martinmiglio for making this happen! If anyone tries this let me know how it goes and if you run into any issues. |
This PR adds an export for a route handler to be used in the latest NextJS App router.
The changes include abstracting out the functionality of the original page router and updating the handler to have a type of
type NextAppRouteHandler = (req: NextRequest) => Promise<Response>;
to match the described syntax of the App Router's Route Handlers.With this change of type, the way responses are made is changed, using
NextReponse.json()
andNextResponse.error()
To implement this route in the App router, something like the following would be used:
Relates to #154