0

I'm trying to figure out how to do something, and I can't quite seem to get it to work. Let me describe the situation:

Using a hosts file, we redirect the resources (CSS/JS/etc) of a website, let's say blah.website.com, to our local machine 127.0.0.1.

We then can do some development on any JS/CSS/etc on our local machine. Let's say the only change we do is making the background: green;.

This allows us to see our changes to the website, blah.website.com without messing with anyone else's view. Only our computer can see the green background when we go to blah.website.com; if anyone else goes there, they don't see it. E.g., if a resource, the.css on the website is located at blah.website.com/the.css, we can have our own version of the.css on our local machine somewhere (127.0.0.1) that is loaded instead (assuming I've set up the hosts correctly, which I have).

Here's where my problem comes in: I want to be able to see these changes on other devices, such as a phone. That is, when I go to blah.website.com on a different device, such as my phone, I want to see the green background. Note that I want to do this without changing the files on blah.website.com.

How can I do this? (Please note: I have to develop on OSX :P)

Steps I've taken: I've tried sharing internet with the phone (have my laptop broadcast WiFi that my phone can connect to), however, despite the laptop being able to see the green background, my phone can't. It seems the phone ignores the hosts file on the laptop, even though the laptop is what is supplying the internet.

Thanks all :)

EDIT:

Also, I'd like to clarify:

Only our local machine (let's say our laptop) has the changes. The server and the second device (let's say our phone) do not have the changes. Ideally, no changes should be made to the second device (e.g., the second device's hosts file) in order for it to see the green background. That is, the second device should just connect to the laptop or something like that and be able to see the changes as well.

  • Possibly helpful: How to edit 'etc/hosts' file? – Dan Pichelman Jul 28 '16 at 15:52
  • @DanPichelman ugh that's the only thing, I don't want to have to change anything on the phone. Plus I'm unsure if iOS devices can change the hosts file. – large hat Jul 28 '16 at 15:57
  • 2
    Why don't you host a server on your development computer which has a unique domain, different from other employees' development computer? – Vincent Savard Jul 28 '16 at 16:04
  • That sounds good, and we do something like that (it's Docker I believe that does that?) to develop on localhost / 127.0.0.1. It's hard to explain. The website that's on the companies' development server is different than the one that is pulled through git version control and developed on localhost. I am able to get a device to connect to the laptop's IP address to view the localhost "version" of the website. However, when it comes to doing development on the companies' dev domain, we use a hosts file that also uses the same CSS as the localhost one due to hosts file trickery. – large hat Jul 28 '16 at 17:46
  • But connecting to the dev server and also seeing the changes which live on the development laptop, like I can do on the localhost version through the laptop's IP, I cannot figure out. I can't quite just connect to the laptop's IP, and sharing internet seems to be close but no cigar. I apologize if I'm misunderstanding your statement. – large hat Jul 28 '16 at 17:48
1

I found a solution to the problem.

First, you set up a shared internet connection (this is doable in OS X's settings, and I know Windows has a similar solution). The shared internet lets your phone connect to your laptop as if it was a Wi-Fi router.

After this, you use brew to install dnsmasq, and you can specify domains which you can force an ip address on in its config file, dnsmasq.conf. Here, I forced domains pertaining to the dev server (blah.website.com) to be that of the local machine. The IP address of the local machine was just like a routers', 192.168.2.1. Also, a hosts file had to be specified (I'm not sure if this is necessary, but if I don't, it doesn't work) which also pointed the dev server domains to the local machine (192.168.2.1).

Once I was connected to the laptop through a second device, you can visit blah.website.com and it will display the changes you've made to the website.

I'm unsure if dnsmasq is available for Windows systems, as you have to compile dnsmasq or use something like brew or apt-get to install it. You probably could just use cygwin or something ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.