While Sunra’s API endpoints can be accessed directly from client-side code, storing API keys in such environments poses significant security risks. To address this, developers typically create custom server-side APIs that securely interact with third-party services like Sunra before returning results to the client. Although effective, this approach often distracts teams from focusing on their core business objectives.

To streamline this process, we’ve developed client libraries that support a proxy mode. This feature enables you to utilize the client libraries in your frontend code while maintaining API keys securely within your server-side infrastructure.

Pre-Built Proxy Solutions

We offer pre-built proxy solutions for several popular frameworks:

  • Node.js with Next.js: a Next.js API route handler that can be used in any Next.js app. It supports both Page and App routers. We use it ourselves in all of our apps in production.
  • Node.js with Express: an Express route handler that can be used in any Express app. You can also implement custom logic and compose together with your own handlers.

We are committed to expanding our offerings based on community feedback. If you have specific requests or suggestions, please join us on Discord to share your thoughts.

Setting Up the Proxy

To integrate the proxy functionality, configure your client by specifying the proxyUrl in your settings:

import { sunra } from "@sunra/client";

sunra.config({
  proxyUrl: "/api/sunra/proxy",
});

This setup ensures that API calls are routed through your server, enhancing security and simplifying development.