• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

How To Proxy Node.js Requests In MAMP & MAMP Pro

Node.js · November 11, 2014

If you are like me you not only develop in PHP, but you also dabble in other languages like Javascript and Node.js, then this blog post is for you. I like to write API servers in Node.js and interface with them in my AngularJS applications.

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.

Dwayne

Leave a Reply Cancel reply

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
suericgp
suericgp
8 years ago

It didn’t work for me. How does MAMP PRO know where is the DocumentRoot at that particular VirtualHost??

1
Brent Phillips
Brent Phillips
8 years ago

Thank you, that is exactly what I was looking for. worked like a charm.

0
Net Guy
Net Guy
7 years ago

Very Nice Tip..!! It worked awesome..

0
Oscar
Oscar
6 years ago

Did not work for me ;(

0

Primary Sidebar

Popular

  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • Thoughts on the Flipper Zero
  • Waiting for an Element to Exist With JavaScript
  • How To Paginate An Array In Javascript
  • Handling Errors with the Fetch API
  • ChatGPT Stopping Part Way Through a Response? Here Is How You Fix It
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • How to Use Neural DSP Archetype Plugins With the Quad Cortex
  • How To Mock uuid In Jest

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz