Ngrok for api and web

I’m working with web hooks and OAuth from Slack and other services so I’ve been using ngrok to get my environment setup correctly for that testing. I wanted to quickly share my config because I ran into a limit with the current ngrok docs on CORS.

When I tried to run two different clients at the same time ngrok http 8910 and ngrok http 8911 I got an error from ngrok about my free account not supporting multiple clients running at once. However you’re able to run two tunnels with a single client and free account but you need to do it differently. And I actually like the different setup anyway.

Instructions

Find your ngrok.yml file by running this config check command:

ngrok config check

Open the ngrok.yml file in the location returned and add this:

tunnels:
  api:
    proto: http
    addr: 8911
  web:
    proto: http
    addr: 8910

Now you can start ngrok tunnels for both the web and api at once by running :sparkles:

ngrok start web api

:smile_cat:

Since I leave the ngrok terminal running off on its own, when I want to grab the URLs I use this:

curl -s http://localhost:4040/api/tunnels | jq '.tunnels[] | "\(.config.addr) --> \(.public_url)"'

"http://localhost:8910 --> https://b-l-a-a-a-h.ngrok.io"
"http://localhost:8911 --> https://b-l-a-a-r-g.ngrok.io"

Thanks!

Related — one of the reasons we implemented a set of test tools for Redwood Webhooks was explicitly to avoid having to setup forwarding like with ngrok.

See Serverless Functions (API Endpoints) | RedwoodJS Docs

WHY TESTING WEBHOOKS IS HARD

Because your webhook is typically sent from a third-party’s system, manually testing webhooks can be difficult. For one thing, you often have to create some kind of event in their system that will trigger the event – and you’ll often have to do that in a production environment with real data. Second, for each case you’ll have to find data that represents each case and issue a hook for each – which can take a lot of time and is tedious.

Maybe thee is something to reuse there to test without being connected.