node.jslaravelvalet

How to setup a custom local domain name for a Node app similar to laravel valet?


I use Laravel valet as my local server and with that, it takes my project folder names and uses them as local domain names. So if I make a folder called test-website, I can now access that in the browser by going to test-website.test.

Starting up a node app, the only way I can access the app in the browser is by going to localhost::3000. That's fine and it works but I'd much rather a custom domain name e.g. new-node-app.test. Is there any way to do this and even better, is there any program out there that can automate this like Laravel Valet does?


Solution

  • You can use Laravel Valet to create a proxy.

    valet proxy [--secure] [--] <domain> <host>
    

    so you could do something like this to make https://node.test work as expected.

    valet proxy --secure node.test http://127.0.0.1:3000
    

    Note: proxies are forwarding requests to an existing service. So do not point your proxy to https://127.0.0.1:3000 unless you are already serving https.

    Works with subdomains too. So if you were running a socket server, you may prefer to use subdomain of io or something.

    valet proxy --secure io.mydomain.test http://127.0.0.1:3000
    

    to verify you have the correct configuration. You can list proxies using valet proxies or delete a proxy by using valet unproxy