When you start to develop custom middleware for the Sitecore OrderCloud (create Webhooks, Integration Events) you start to think about how you can test/debug your features. Since Sitecore OrderCloud is a SaaS cloud-based platform, your middleware must be public. In other words, middleware must be accessible through the internet.
Of course, we can deploy custom middleware to Azure. It will require to build CI/CD pipeline for that. Even if you will need to test something, you have to deploy your changes to Azure. This solution looks good for QA/UAT/Stage deployments, but not for DEV, because as a developer I want to avoid any deployment to Azure before I test and debug it. I would keep everything locally. How can I do that?
We need a solution, which can make our middleware endpoint available for the public. Is there any solution for that? Yes, there is!
Ngrok Website: https://ngrok.com/
Ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels.
It has different paid plans, but also includes a free plan:
- HTTP/TCP tunnels on random URLs/ports
- 1 online ngrok process
- 4 tunnels / ngrok process
- 40 connections / minute
In case of a free plan, if you stop and restart the ngrok process, the ngrok URL will change. A paid ngrok account will give you a dedicated URL. It means that you have to update the Payload URL for Webhooks and Integration Events every time when you restart the ngrok process. Just keep this in mind!
Download and run a program on your machine and provide it with the port of your middleware.
Local representation of Swagger:
Ngrok: ngrok http https://localhost:6001 -host-header="localhost:6001"
The middleware port can be different in your case and can be changed to yours.
Now you can copy the new created host by ngrok and try to call your custom endpoints via Postman:
Ngrok also provides the web interface.
Usually, it can be accessible by this URL: http://127.0.0.1:4040
There are some alternatives to ngrok:
-
Localtunnel.
-
Serveo
-
Teleconsole
-
Pagekite
It’s up to you which tool you want to use. I prefer to use ngrok because it covers all my development needs.
Happy coding!