This is an Enterprise only policy at this time. Please contact us to trial this or sign up for an Enterprise account.
The WebSocket Handler enables you to manage WebSocket connections to your backend WebSocket APIs. It can be configured alongside other existing policies like Rate Limiting, API Keys, etc. and is available for use on all environments.
This handler is currently in beta and only configurable via the JSON View on a
project's Route Designer or directly in your project's
Setup in routes.oas.json
Configuration of the WebSocket Handler is similar to other available handlers.
Set the name of the path that your WebSocket API route will use, set the use of
webSocketHandler export from
@zuplo/runtime module in the handler
configuration and use the
rewritePattern property inside of
options to point
to your service's WebSocket API endpoint.
Your configuration will look like below:
"summary": "Zuplo websocket route to internal API",
"description": "Zuplo websocket route to internal API",
The WebSocket Handler can be configured via
options property. It has the
following configuration properties
rewritePattern- the URL the incoming pathname will be appended to.
Similar to other handlers using
interpolation syntax and can be used to shape the URL based on data from the
incoming request and environment variables defined in the project.
The following objects are available for substitution:
env- the environment object, to access Environment Variables
request: ZuploRequest- the full
context: ZuploContext- the
ZuploContextobject without functions.
params: Record<string, string>- The parameters of the route. For example,
params.productIdwould be the value of
:productIdin a route.
query: Record<string, string>- The query parameters of the route. For example,
query.filterBywould be the value of
headers: Headers- the incoming request's headers object
url: string- The full incoming request as a string
host: string- The
hostportion of the incoming URL
hostname: string- The
hostnameportion of the incoming URL
pathname: string- The
pathnameportion of the incoming URL
port: string- The
portportion of the incoming URL
searchportion of the incoming URL
Use the following methods to encode portions of the URL:
encodeURIComponent()function encodes a URI by replacing each instance of certain characters with escape sequences.
e: An alias to
encodeURIComponentto help keep URLs more readable. Can be used like
A few examples of the values of various substitutions.
Different Backends per Environment
It's common to want to use different backends for your production, staging and preview environments. This can be easily achieved by using environment variables to specify the origin of the backend.
options you can combine the
environment variable, say
https://example.com to achieve this.
// Runtime value is