node.jsruby-on-railsnext.jsrails-api

Pass through NextJS frontend requests to NextJS API first and then to Rails API or directly to Rails APi?


I am developing an App which consists of a NextJS frontend and a Rails API backend.

There is this /api route from NextJS where I can put "server side code". Should I use this feature by sending my frontend requests first to that /api endpoint and then to the Rails API endpoint or is "ok" to directly send the requests to the Rails API endpoint?

For me that looks a bit like a "jump around the corner".

Are there true benefits using the NextJS frontend -> NextJS API -> Rails API approach?


Solution

  • No

    From next js docs:

    Use Cases

    For new projects, you can build your entire API with API Routes. If you have an existing API, you do not need to forward calls to the API through an API Route. Some other use cases for API

    Routes are:

    https://nextjs.org/docs/api-routes/introduction#use-cases