⚠️
The vite-plugin-ssr project has been renamed Vike.
  • If you are already using vite-plugin-ssr then migrate to Vike.
  • For new projects, don't use vite-plugin-ssr but use Vike instead.

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.