By Robbie | July 10, 2020
In this tutorial you’ll learn how to test your mobile app with a locally hosted backend using Expose.sh.
You can use any kind of mobile app running on any platform for this guide. Native, web, iOS, Android apps and even just regular websites will all work equally well.
For Mac or Linux, go to Expose.sh and copy/paste the installation code shown into a terminal.
For Windows go to Expose.sh, download the binary and put it somewhere in your PATH.
Expose your backend api to the web
Start your API server on your development machine. For the purposes of this guide, i’ll assume it runs on port 80.
expose 80. Replace 80 with the port your API is listening on if it is different.
Expose.sh will generate a random public expose.sh URL. You’ll see output like
https://s3rh.expose.sh is forwarding to localhost:80 http://s3rh.expose.sh is forwarding to localhost:80
Configure your mobile app to call your new expose.sh domain
Lets say your mobile app will call
/login when log in credentials are entered in to the log in screen.
Configure your mobile app to use the domain shown in the expose output. Using the output above it would be
https://s3rh.expose.sh. Add the route for your API if it exists
for example if your API lives at the route
/api/v1/, configure your mobile app to use the endpoint
When you log in via the mobile app, the app will contact your back end api which is running locally via the Expose.sh service.
You can now use your debugger, logging and other tools. Changes are faster as you don’t have to deploy to a remote server or wait for CI builds anymore.
Using a custom subdomain (like myapi.expose.sh) would save you from needing to reconfigure the API endpoint each time.
Expose.sh is free to use for randomly generated subdomains. If you want to use your own custom subdomains like “myapi.expose.sh”, you can do this for as little as $5/month depending on how many domains you want to use. Its usually a good time vs money investment, considering the hourly rate of most people who use expose.sh for work. Sign up here.
As you can see, using Expose.sh to test a back end API makes a lot more sense than building and deploying your API to a remote server. Its also faster and much easier to configure than some other alternative methods that could be used to enable your app to communicate with your dev machine, such as ADB for Android.
Happy coding!Get started here