Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Windows support #11

Open
mdlawson opened this Issue · 24 comments

5 participants

@mdlawson
Collaborator

I've been looking into how to get the whole hoodie setup working on windows, and my starting point has been local-tld, as its the least cross platform element currently, and just the concept seemed quite cool for other uses.

After researching a bit around window's host resolution system, it sadly seems the only way to implement local-tld's functionality is to use the hosts file.
The only functionality that cant be replicated this way is the use of firewall rules to redirect traffic on port 80 to port 5999, where a http server runs, but I'm not sure what purpose this has, as listening on port 80 would be identical, right?

The only other piece of missing functionality once the dns resolution is dealt with is the service, which I'm pretty sure is easy to implement on windows thanks to [node-windows] https://github.com/coreybutler/node-windows

So, as for the ugly, modifying the hosts file job, I'm suggesting something like this, https://gist.github.com/mdlawson/5355459 (sorry for the coffeescript, I can quickly clean up the generated js as needed) which wraps up the modified section in an application specific tag, and doesn't touch the rest of the file.

Usage is like this at the moment, but easy enough to change:

hosts("local-tld",function(){
  // read, ready for modification
  this.add("test.dev","127.0.0.1");
  this.remove("test2.dev","127.0.0.1");
},function(){
  // written, cache flushed
});

produces output like:

### BEGIN local-tld ###
127.0.0.1 test.dev
### END local-tld ###

at the end of the users hosts file

I'm aware that its a horrible solution, but short of replacing the users DNS server with a 3rd party one and then hacking up that instead, I cant see a better way.

Let me know what you think.

@janl
Owner

We need to look into something simliar for linux (cc @caolan) I think being able to edit /etc/hosts and work with ports instead of custom dns is a fine way to get this done. We can always make it even nicer later.

@janl
Owner

And thanks for looking into the windows side! :)

@mdlawson
Collaborator

unix /etc/hosts is exactly the same structure, so my snippet should work if the value of HOSTS is swapped out, and the line endings are fixed to be cross platform. Its a bit messy, but I think its probably the safest way of doing things. Ill look into it, and see about integrating things up properly into a pull request.

@janl
Owner
@mdlawson
Collaborator

Updated my gist with cross platform ready code, not entirely sure how to best do a pull request though, depends on if the dns trick is still going to be used on mac os or the hosts file can be used there as well.

strike that, got some bugs. Ill fix it up.

Panic over, os.EOF instead of os.EOL is a pretty stupid typo.

@mdlawson
Collaborator

Working on more or less a rewrite on my fork https://github.com/mdlawson/local-tld on the crossplatform branch.
Windows support, including a service, has been implemented so far. I will port over the existing mac service install soon, after I improve usability a bit. I plan on writing an init.d initscript and a systemd unit for linux as well.
I added a CLI interface for managing the service, which I feel is better than using npm install/remove hooks.

xip.io support has been removed for now, ill add it as soon as I work out what the existing code even does, and how best to do it in windows.

@gr2m
Owner

wow, thanks so much for working on this @mdlawson. This is so awesome!

@mdlawson
Collaborator

I've added mac os support in my fork, but I have no way of testing if it works. If someone could check it out, that would be awesome.

After cloning and npm installing, you should try: (needs root)

node lib/local-tld.js service install

followed by

node lib/local-tld.js service start

and then test if stop and remove work as well.
Error reporting is really unfriendly right now, just throws errors if encountered.

It would also be a nice to test the service separately, even if the manager doesn't work, by running

node lib/service.js

Thanks!

@mdlawson
Collaborator

Ok, I'm fairly sure my branch has all the existing features working on windows. I've just setup a mac vm for testing macOS, so i'll get that working soon.

One concern where it probably differs at the moment is the config file. What format is it supposed to be in? My branch currently reads/writes the format:

{
    "myfancyprojectA": {
        "port": 8000
    },
    "test": {
        "port": 3000
    }
}

After I've made sure everything works as expected on mac, perhaps my branch could be merged into a branch in this repo, pending merge into master? Not really sure how to contribute a rewrite.

@janl
Owner
@mdlawson
Collaborator

Just checked the readme and saw that new format. Doh! Should be trivial to switch over though.
Took a quick look over node-multicouch, doesn't look like much work to fix up. Only obvious thing I saw was "/" directory separators in path compositions all over the place, which generally just need replacing with calls to path.join().

When I'm happy with local-tld, I'll move on to that.

@janl
Owner
@mdlawson
Collaborator

Just tested everything out on MacOS, by some miracle it all works ok. Not sure what to do about linux support really, since init systems vary by distro and its normally up to the package maintainers for the distro to sort it out. Might just leave linux with commands to start the service in the current terminal, with no daemonization. How does that sound to you?

@janl
Owner
@Acconut

I would like to see support for wildcards in local-tld on windows. I'm not sure how linux etc. handle wildcards in the hosts file but as far as I'm concerned Mac does support it.
Sadly windows doesn't so we must use a local dns server for that.

I'm going to do some research but for now this is quite interesting: http://stackoverflow.com/questions/138162/wildcards-in-a-hosts-file

I've also seen some dns server written in raw node, so maybe one of these could be an option.

This could be ported to nodejs:
https://code.google.com/p/marlon-tools/source/browse/tools/dnsproxy/dnsproxy.py

@mdlawson
Collaborator

Really not sure on the whole "embedded dns server" thing. Using a binary dns server would mean embedding something for windows, and probably embedding dnsmasq or requesting its installation for linux users. Both of those then need configuring and managing. This just seems horribly messy, given the existing, reasonably unified codebase.
Using a node dns server seems a bit irresponsible: A dns server needs to be totally bulletproof. Existing nodejs solutions don't look too solid, and I wouldn't feel comfortable making one that is any better.
Then, in adition, we give ourselves the problem of changing the users dns server cross platform. This could be done by asking the user to do it (hardly "works out of the box") or doing automatically (seems like a horrible idea to change a system setting just for this, and would introduce lots of ugly platform specific code)

Just my thoughts on the issue.

@Pomax

loving the idea of being able to use this cross-platform... completely sidestepping question: would this work on windows if it has Bonjour installed on it? (comes with itunes, and certain adobe creative suit components)

@mdlawson
Collaborator

loving the idea of being able to use this cross-platform... completely sidestepping question: would this work on windows if it has Bonjour installed on it? (comes with itunes, and certain adobe creative suit components)

Interesting. I'm not familiar with bonjour, but from a very brief delve into the bonjour dev stuff (https://developer.apple.com/bonjour/) It looks relevent. I'd be interested to hear how your envisage that working.
I dont thing bonour on windows is generally well recieved by devs, but it may still be a more friendly option than changing nameservers, or messing with the users hosts file

@Pomax

I took "This uses a cool dynamic DNS system that is built into Mac OS X." to mean that is uses Bonjour, since that's the only dynamic DNS I know comes with OSX, so I figured having Bonjour available on other systems would go a long way to make things work =)

I haven't actually tried to see if it works, but I might try to see if I can get it to work tomorrow. We're using a multi-app setup using nodejs where we need to do some localhost testing with cookies and subdomains, cross-platform local-tld would be awesome.

@mdlawson
Collaborator
@gr2m
Owner

I'm not the guy who has build that, @janl did, but I know it was heavily inspired by pow.cx and its architecture

@janl
Owner

bonjour is irrelveant to this discussion.

Bonjour is for discovering network services, not for DNS resolution. (although that is kinda part of it).

Say local-tld creates a service on a host, one can use bonjour to find that service from other machines on the local network.

@Pomax

interesting. curious about the hinted-at OSX bit of dns coolness then, though: which component does local-tld hook into to get the job done?

@janl
Owner

man resolver :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.