Refactor: Move api endpoints to app router #93
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR transitions the API endpoints from the
pages
router to the newapp
router, marking TurboETH's complete migration to theapp
router and eliminating thepages
folder. This move also standardizes the implementation of API endpoints for integrations.Now, every API endpoint associated with an integration should be located inside the
integrations
folder. For instance, if theopenai
integration requires anask
endpoint, the corresponding code should be housed inintegrations/openai/api/ask.ts
. The endpoint functions must maintain the Next convention for route handlers, employing named exports based on the HTTP method (GET, POST, PATCH, etc.):To expose the endpoint, the route handler file must reside at
app/api/(integration-name)/(endpoint-name)/route/ts
. For instance, theopenai
endpoint should be atapp/api/openai/ask/route.ts
:This pattern applies to all migrated API endpoints and should be adhered to for any new additions.
The major obstacle in this migration was the lack of support for
app
router API endpoints from iron-session. The workaround employed thegetIronSession
method with an emptyResponse
object to retrieve thesession
object, instead of using the unsupportedwithIronSessionApiRoute
wrapper. Upon the launch of iron-session V8, which promises first-class support for theapp
router, the endpoints utilizing it will be updated accordingly.