vite-plugin-ssr has been renamed Vike, see migration guide.

API Routes

Vite-plugin-ssr doesn't implement API routes by design. We believe decoupling the API is a more robust approach.

Instead use:

  • Telefunc

    Telefunc is a simple solution providing a much better DX than API routes. Out of all options, we recommend Telefunc most.

  • tRPC

    Similar to Telefunc.

    • Con: Telefunc is simpler.
    • Pro: supports real-time endpoints with websockets.
  • Use your server to create new HTTP endpoints (such as Express.js routes). That way you'll get a DX similar to API routes.

    If you use this technique then:

    • Make sure vite-plugin-ssr's middleware is your last middleware.
    • When modifying your server, you may need to manually restart your server for your changes to take effect.

    See explanation at API > renderPage().

  • GraphQL


    If you aren't a very large team, then GraphQL is most likely over-engineering. RPC (such as Telefunc and tRPC) is simpler, and actually more flexible as long as you aren't a very large team.

    We recommend getting started with RPC and use GraphQL only later if/when the need arises.