HomeWiki
HomeWiki
  1. Home
  • Back to home
  • 7. Proxies
  • Using Proxies
  • Transformations
  1. Home

Using Proxies

Using Proxies in Shopranos to Call External URLs#

In the Shopranos platform, proxies allow you to securely call external URLs from the eShop frontend. This approach helps you overcome challenges such as CORS issues, API key exposure, and ensuring proper authorization and permissions. By setting up a proxy, you can manage external calls efficiently and safely within the Shopranos environment.

Benefits of Using a Proxy#

1.
Avoid CORS Issues:
The proxy acts as an intermediary, making the external call server-side through Shopranos. This bypasses any cross-origin restrictions, allowing your frontend to operate smoothly.
2.
Hide API Keys:
You can securely inject sensitive information, like API keys, into the proxy configuration. This ensures that the frontend never directly handles or exposes this data.
3.
Ensure Shopranos Authorization:
Proxies can be configured to make authenticated calls, adhering to Shopranos' authorization rules and permissions. This ensures that only authorized users can make specific API calls.
4.
Request and Response Transformation:
Use JavaScript to modify requests before they are sent or to transform responses before they reach the frontend. This allows for customized data handling to fit your needs.

How to Set Up a Proxy#

1.
Define the External URL:
In the proxy settings, specify the external URL that you want the proxy to call.
image.png
2.
Inject Headers or Parameters:
Add any necessary headers or parameters, such as API keys, to be included in the request.
image.png
3.
Configure Authentication and Permissions:
Set up the proxy to require Shopranos authentication if needed, and define the necessary permissions for the call.
image.png
4.
Use JavaScript for Transformation:
Implement custom JavaScript to transform the request or response. This can include formatting data, adding/removing fields, or any other necessary adjustments. View More

Example Scenarios#

CORS Issue:
If your frontend needs to call an external API that does not allow cross-origin requests, the proxy will handle the request server-side, avoiding CORS issues.
Secure API Key:
Instead of exposing your API key in the frontend, you can securely inject it into the proxy request. This keeps your API key hidden from users.
Shopranos Authorization:
Ensure that only authenticated users with the correct permissions can make certain API calls by configuring the proxy with Shopranos authorization.

How It Works#

1.
Create a Proxy:
Define the external URL, and configure the necessary headers, parameters, and authentication.
2.
Shopranos Generates a URL:
Shopranos will provide you with a custom URL that you can use in your frontend code, pointing to the proxy you've created.
3.
Frontend Makes a Request:
Instead of calling the external URL directly, your frontend will call the Shopranos-generated URL. This avoids CORS issues and keeps sensitive information secure.
4.
Shopranos Handles the Call:
The Shopranos platform processes the request, applies any necessary transformations or injections, and forwards the call to the external URL.
5.
Response Handling:
The response from the external service is returned to Shopranos, where it can be further processed or transformed before being sent back to your frontend.

Example Flow#

Frontend Request: Calls https://your-shopranos-url.com/proxy-endpoint
Shopranos Proxy: Internally forwards the call to the external URL, e.g., https://api.external-service.com/resource
External API Response: The external service responds to Shopranos.
Shopranos Processes Response: JavaScript transformations or filtering are applied.
Frontend Receives Response: The processed response is sent back to the frontend.

Benefits Recap#

Security: Sensitive data like API keys remain hidden from the frontend.
Simplified Authorization: The proxy call inherits Shopranos' authentication and permission systems.
Cross-Domain Compatibility: CORS issues are avoided by keeping the call server-side.
By leveraging the Shopranos-generated URL, your frontend benefits from enhanced security, flexibility, and seamless integration with external services, ensuring smooth operation and secure data handling.
Next
Transformations
Built with