Skip to content

feat: split api routes into separate functions #1495

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

Merged
merged 30 commits into from
Oct 17, 2022
Merged

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jul 31, 2022

Summary

Rather than including API routes in the SSR function, this splits them into individual functions per route. This makes them smaller, easier to track in the UI, and enables them to be configured individually.

Test plan

  1. Visit the Deploy Preview
  2. Open the API route examples

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/634d839bd7f54700084d2a76
😎 Deploy Preview https://deploy-preview-1495--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/634d839ba18ea400092e4343
😎 Deploy Preview https://deploy-preview-1495--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/634d839ba787480008f4d097
😎 Deploy Preview https://deploy-preview-1495--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/634d839b9bea8e0009c9c9e8
😎 Deploy Preview https://deploy-preview-1495--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jul 31, 2022
@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for next-hp-edge-demo ready!

Name Link
🔨 Latest commit 898a8a7
🔍 Latest deploy log https://app.netlify.com/sites/next-hp-edge-demo/deploys/633ff3cfc903030009ddbf4a
😎 Deploy Preview https://deploy-preview-1495--next-hp-edge-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for next-plugin-rsc-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-rsc-demo/deploys/634d839b7366320008ced7b1
😎 Deploy Preview https://deploy-preview-1495--next-plugin-rsc-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/634d839b5cb15c00098c9f3e
😎 Deploy Preview https://deploy-preview-1495--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/634d839b89d8700009d14b24
😎 Deploy Preview https://deploy-preview-1495--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/634d839b414f1a000802fa18
😎 Deploy Preview https://deploy-preview-1495--next-plugin-canary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/634d839b9775ac0008e88cc7
😎 Deploy Preview https://deploy-preview-1495--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jul 31, 2022

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 781be0c
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/634d839b23e05f00080e06f0
😎 Deploy Preview https://deploy-preview-1495--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@cypress

This comment was marked as outdated.

@cypress
Copy link

cypress bot commented Jul 31, 2022



Test summary

2 0 0 0


Run details

Project netlify-plugin-nextjs-nx-monorepo-demo
Status Passed
Commit 2b22248 ℹ️
Started Aug 8, 2022 10:55 AM
Ended Aug 8, 2022 10:56 AM
Duration 01:10 💡
OS Linux Ubuntu - 20.04
Browser Chrome 103

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@cypress
Copy link

cypress bot commented Jul 31, 2022



Test summary

7 0 0 0


Run details

Project netlify-plugin-nextjs-static-demo
Status Passed
Commit 2b22248 ℹ️
Started Aug 8, 2022 10:54 AM
Ended Aug 8, 2022 10:56 AM
Duration 01:19 💡
OS Linux Ubuntu - 20.04
Browser Chrome 103

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@ascorbic ascorbic force-pushed the mk/background-functions branch from 902f75d to dc8c3de Compare July 31, 2022 14:23
@ascorbic ascorbic force-pushed the mk/background-functions branch from 8c35268 to 5f582b2 Compare August 8, 2022 10:51
@ascorbic ascorbic force-pushed the mk/background-functions branch from dd87de6 to 00a80a7 Compare August 19, 2022 12:19
@ascorbic ascorbic marked this pull request as ready for review October 6, 2022 08:24
@ascorbic ascorbic requested a review from a team October 6, 2022 08:24
Comment on lines +3 to +4
Cypress.Cookies.debug(true)
cy.getCookies().then((cookie) => cy.log('cookies', cookie))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these debug lines still necessary?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following up on this @ascorbic

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last ping about this. It's not a blocker, but I assume it was only for debugging purposes?

@nickytonline
Copy link

It looks like the demo site for the split API routes is failing @ascorbic.

5:40:25 AM: Error: > Couldn't find a `pages` directory. Please create one under the project root
    at Object.findPagesDir (/opt/build/repo/node_modules/next/dist/lib/find-pages-dir.js:42:19)
5:40:25 AM:     at /opt/build/repo/node_modules/next/dist/build/index.js:95:70
5:40:25 AM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
5:40:25 AM:     at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:65:29)

@ascorbic
Copy link
Contributor Author

@nickytonline you have two copies of the plugin in your site. You need to disable to auto-installed one.

@ascorbic ascorbic requested a review from nickytonline October 17, 2022 08:22
Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected an HTTP 202 is returned for the background function in the demo, i.e. /api/hello-background

CleanShot 2022-10-17 at 16 27 49

And for a scheduled route, i.e. /api/hello-scheduled, it correctly returns an HTTP 404.

CleanShot 2022-10-17 at 16 29 34

Nice work @ascorbic!

@kodiakhq kodiakhq bot merged commit 654c6de into main Oct 17, 2022
@kodiakhq kodiakhq bot deleted the mk/background-functions branch October 17, 2022 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants