1. Create an endpoint for your service
Start an internal Agent Endpoint, replacing$PORT based on where your service listens.
You can also use one of our SDKs or the Kubernetes Operator.
2. Reserve a domain
Navigate to the Domains section of the ngrok dashboard and click New + to reserve a free static domain likehttps://your-service.ngrok.app or a custom domain you already own.
We’ll refer to this domain as $NGROK_DOMAIN from here on out.
3. Create a Cloud Endpoint
Navigate to the Endpoints section of the ngrok dashboard, then click New + and Cloud Endpoint. In the URL field, enter the domain you just reserved to finish creating your Cloud Endpoint.4. Add routing to your service and error handling with Traffic Policy
While viewing your new cloud endpoint in the dashboard, copy the policy below and paste it into the Traffic Policy editor.https://service.internal.
If forwarding to https://service.internal fails, the on_error: continue configuration on your forward-internal action means that the policy continues to the next rule, which sends a custom 503 error response with the HTML specified in the body.
5. Try out your endpoint
Visit the domain you reserved either in the browser or in the terminal using a tool likecurl.
You should see the app or service at the port connected to your internal Agent Endpoint.
If you take down either your upstream service or the internal Agent Endpoint, you’ll see your custom error message.
What’s next?
- See other examples of using the
custom-responseto create error pages or messages, such as a JSON-based response for an API service. - View your traffic in Traffic Inspector to see who and when users hit your custom error page.
- Add the
logaction before thecustom-responseto send error events over to your observability platform for enriched debugging.