Running ngrok To Use Local Open Event API Server Endpoints From Public Access URL
While developing the nextgen Open Event API Server, one has to let co-developers review the changes made for each new feature added or any bug fix made. One way to do this is to fetch code from pull request head and setup a local deployment from the PR branch. This sometimes causes issues in database due to faulty migrations, if one is not careful. One other way, which is discussed in the blog post here, is using ngrok. What is ngrok? Ngrok lets you create a secure tunnel to your localhost deployment over a public URL. This particular feature comes in handy when you have changes, say along with a populated database, to demo to someone else over a public url, which can be shared between as many people. It saves you from deploying the change branch over again and saves you from hassles of database migration issues. How to setup and run ngrok? To run ngrok, you need to download it from the ngrok website. The download page can be found here. Once you have the zip installed, you’ll need to unzip it. On Linux or MacOS, run this in the terminal: $ unzip /path/to/ngrok.zip To expose the web server running on your local machine, run the following from inside the directory where you have unzipped ngrok: ./ngrok http 80 This syntax breakdowns to : ngrok :: terminal command http :: protocol of the server that is to be tunneled ( ngrok also lets you open and run TCP and TLS tunnels) 80 :: port on which the tunnel is to be run ( If you are not sure of the port on which your server is running, it might probably be 80 - the default for HTTP) The Open Event API server runs on port 5000 and it provided HTTP API, so the command we’ll use here is ./ngrok http 5000 Once you run this command, ngrok opens its UI in the terminal itself. This will contain the public url of your tunnel along with other stats related to the requests being made and traffic on localhost. Starting ngrok: Public URL updated: ngrok also offers a web interface where you can see the requests and other data which is shown in the terminal. For this go to http://localhost:4040/inspect/http. This web interface inspects and records each request made so that you can replay the requests again for debugging or cross-checking metrics. This feature can be turned off by passing an argument, so that the requests are not recorded anymore. While running a production server, it can help to both maintain security for the requests and also reduce request handling times when scaling. To read more about advanced options, please read the ngrok documentation. Running Open Event API server on the public URL: Since now we have localhost:5000 tunnelled over a public url, we’ll use that to make requests to the API server. A GET request for /v1/events : The request made to the public URL, which in this case here is: http://9a5ac170.ngrok.io is equivalent to…
