How can I set up local development with subdomains using Fastify?

0
0
Asked By ChillWavez99 On

I'm trying to develop my app locally with subdomains, specifically trying to access something like test.localhost:3002, but I'm hitting a network error when I try to make API requests to my Fastify server. How do others manage local development with subdomains while using a Fastify server? Any tips would be really appreciated!

3 Answers

Answered By QuickFixDev On

Just a heads up, using 'localhost' as a subdomain isn't entirely valid. You can run your Fastify server on different ports instead of trying to access them as subdomains. Each app can run on something like localhost:3001, localhost:3002, etc.

NextGenDev -

But isn’t it possible to get subdomains working through DNS?

Answered By TechToTheMax On

Hey! So, the first thing to know is that for subdomains to work on localhost, you need to tweak your 'hosts' file. On Windows, you can find it at c:windowssystem32driversetchosts, and on Mac or Linux, it’s usually /etc/hosts. Open it with admin rights and add this line:

`127.0.0.1 test.localhost`

Don’t forget to save your changes after that! Once you do this, try accessing test.localhost again. Let me know how it goes!

NightOwlDev -

Just to double check, have you restarted your server after making those changes?

User404 -

Thanks for the tip! I’ve added that line, but I'm still facing the same issue. Do you have any more suggestions?

Answered By CodeWizard99 On

Your localhost setup doesn't automatically support subdomains. To get it working, configure your DNS or directly modify the 'hosts' file as mentioned earlier. I also use valet-linux for managing local domains, but I'm not sure how it plays with Fastify specifically. It's super handy though!

DreamCoder77 -

That sounds cool! Is there a similar tool for Mac? I’d love to manage local domains more easily.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.