Because MAMP Pro comes with a useful feature of allowing easy hosts/URL aliasing creation, we can create a virtual URL for our API and then interact with it in our applications.
Before we continue, this post assume that you are using MAMP/MAMP Pro version 3 or greater. It will work in earlier versions too, some menus and screens might be different.
– In the hosts tab, add the URL you want to proxy. So if you want to proxy a url: api.mycoolapp.com to a Node.js server running on port 3000 on http://localhost:3000 click on the plus and add it in. Specify a folder, however this is not important as the folder will be ignored as we are redirecting our request, not loading files from a server.
– Now that we have added in our host, click on it and you should see four tabs; General, Extended, SSL and Extras. By default General will be selected, click on Extended.
– Now that you are in Extended, at the bottom you should see: Additional parameters for VirtualHost and a text area you can write stuff into. This is where we are going to modify the Apache VirtualHost rules and make it redirect. Copy and paste the below code into this box and hit the save button.
ServerName MyCoolApp ServerAlias api.mycoolapp.com ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ ProxyPreserveHost On
And there you have it. You have just created a ServerAlias and ProxyPass modification inside of MAMP. This is powerful in that it allows you to create virtual URL’s for Node.js servers or anything else including Ruby on Rails, Python, etc.