2
3 Comments

Anyone using Next.js for production SaaS with public facing API?

I'm wondering if anyone is using Next.js for their production SaaS preferably with a public facing API. I have two questions/concerns.

  • My SaaS users will need to hit my API directly, most SaaS apps use a subdomain like api.mysaas.com/v1/content, but next forces you to use the api subdirectory like mysaas.com/api/v1/content. Do any of your customers find this odd or unprofessional, or is it not a problem to hit the subdirectory?

  • My SaaS users will need to the my API frequently. Can the Next APIs scale quickly and reliably? Has anyone stress tested them or have daily user analytics they could share? Would be hosted with Vercel if that makes a difference.

on February 24, 2022
  1. 1

    "but next forces you to use the api subdirectory like mysaas.com/api/v1/content"

    I'm not sure what you mean by this. I run a SaaS app using NextJS and Netlify for the front end. My backend is on a subdomain "api.saaswebsitename.com"

    1. 1

      I meant using the built in Nextjs API functionality. I assume you have a separate API server that you’re pointing your subdomain to?

  2. 1

    I've just started using next as API recently so I cannot answer the second question.

    For the first one, I don't see any reason to think /api is in any way not professional. Actually, I prefer sub-paths where possible because:

    • I can set my base url in my frontend as /api, as a result frontend becomes backend-url agnostic. It gives me the power to use a version of the frontend with different versions of the backend. This can be useful for developing in review branches, doing A/B testing etc.
    • I don't need to worry about cors

    There has been some times when I had to have api.mysaas.com, but I ended up proxying mysaas.com/api to it.

    After all it's mostly a matter of preference. Unless you are building an API-First product, none of your customers will notice, even if they do they will not care.

    (if i was unable to convince you until now, here's a solution: just add mysaas.com and api.mysaas.com as domains to Vercel, create a _middleware.js which rewrites /api to / only if the accessed hostname starts with api., and if the hostname does not start with api. block any request coming to /api. all of these should take a couple of lines to implement)