Sunday, September 3, 2023

Setting up NGROK to hit multiple endpoints

 NGROK is a very useful developer tool for working with cloud based services, as it allows testing workflows where those services have to call back to your machine. With NGROK, you can create a temporary public address to hit an endpoint on your machine, so say, a workflow in could hit a GraphQL endpoint to make content updates.

NGROK now supports hitting local HTTPS endpoints, and through the use of configuration, allows you to define tunnets to multiple services on your PC.  This is helpful so that you can expose both your CM and your ID endpoint.

To take advantage of this, when you register for NGROK, on the get-started page Setup - ngrok, make sure to run the "ngrok config add-authtoken <value>" to enable advanced features. 

Then go to $env:LOCALAPPSETTINGS\ngrok\ngrok.yml and add something like this (for XM1 configuration):

     proto: http
     addr: https://xm1cm.localhost
     host_header: rewrite
     proto: http
     addr: https://xm1cd.localhost
     host_header: rewrite
    proto: http
    addr: https://xm1id.localhost
    host_header: rewrite

The "rewrite" line tells NGROK to rewrite the host header entry to match the URL. This is necessary or Traefik (and presumalby IIS) will return a 404.

Now run this to create endpoints:

>ngrok.exe start cm cd id

Three tunnels will be created, and the URLs will be accessible on your command prompt: 

And at NGROK Endpoints - ngrok:

Once you hit Control-C on the prompt where you are running NGROK, those URLs go away, and new ones will be generated for you the next time.  (You can keep them on the paid plan.)

Now hitting the first URL returns this:

And hitting the second gets this: 

Happy cloud service coding!

No comments:

Post a Comment