Code Monkey home page Code Monkey logo

local-tld's Introduction

Local TLD

Build Status Dependency Status devDependency Status

Local TLD maintains a local development top level domain that you can hook various projects into.

If you know pow, this is pow without the Rack part.

Mac OS X only, for the time being. Cross platform support desired, if you can contribute it! :)

Er what?

Here’s an example. What if you maintained two web projects A and B and have a local setup of both, and you’d like to work on them both at the same time, or switch easily, and you don’t want to mess with things like http://localhost:8888 because that is just annoying and ugly.

What if you could have these two nice addresses:

http://myfancyprojectA.dev
http://thatotherprojectB.dev

Yes, you can do that by messing with /etc/hosts, but it ain’t pretty, and you have to do it for every new project and it is ugly.

Setup

$ npm -g install local-tld
  # or for now git clone $thisrepo
$ $EDITOR ~/.local-tld.json
{
  "8000": {
    "name": "myfancyprojectA"
  },
  "8001": {
    "name": "thatotherprojectB"
  }
}

Dat it. ~/.local-tld.json maps the a subdomain to a TCP port. So if you have an httpd running on localhost:8000 you can now reach it by going to http://myfancyprojectA.dev.

I want my app to register itself with local-tld!

See https://github.com/hoodiehq/local-tld-lib

Ok cool, how does it work?

This uses a cool dynamic DNS system that is built into Mac OS X. Local TLD runs a minimal DNS lookup server that does the address translation magic.

I want subdomains!

Easy. Just make your configuration look like this:

{
  "8000": {
    "name": "myfancyprojectA",
    "aliases": ["subdomain1", "subdomain2"]
  }
}

Now, you should be able to reach localhost:8000 from http://myfancyprojectA.dev, http://subdomain1.myfancyprojectA.dev, and http://subdomain2.myfancyprojectA.dev!

Sweet. Does it work with boot2docker ports?

Yep! In addition to the port, you'll need to specify your boot2docker ip address (usually 192.168.59.103) for the domains you want to map:

{
  "192.168.59.103:8002": {
    "name": "myfancyprojectC"
  }
}

(Astute readers will note that this actually means it works with any server on any IP address, not just boot2docker)

No Original Work

This is all ripped out of pow, we don’t claim any credit.

License

Apache 2 License

Copyright

(c) 2013 Jan Lehnardt [email protected]

local-tld's People

Contributors

bobthecow avatar boennemann avatar dgiunta avatar ds82 avatar gr2m avatar janl avatar qmx avatar simianhacker avatar smurthas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

local-tld's Issues

support for multiple apps on the same domain

I would love to see this work:

{
  "4000" {
    "name": "a.mysite.dev"
  },
  "4001" {
    "name": "b.mysite.dev"
  },
  "4002" {
    "name": "c.mysite.dev"
  }
}

It's great for testing cross domain app interactions

LaunchDaemon not starting

When I npm install -g local-tld, the following message shows up in my /var/log/system.log:

Aug  1 14:31:41 maxedmands com.apple.launchd.peruser.501[225] (ie.hood.local-tld-service[15898]): Job failed to exec(3). Setting up event to tell us when to try again: 2: No such file or directory
Aug  1 14:31:41 maxedmands com.apple.launchd.peruser.501[225] (ie.hood.local-tld-service[15898]): Job failed to exec(3) for weird reason: 2

...and then the service just does not work. I'm not sure how to proceed.

sudo: incorrect password attempts

Trying to install local-tld with this command. I use sudo for install at /usr/local/lib
But the post-install script ask me to enter sudo password again. Same password but failed.

⚡  sudo npm install -g local-tld
npm http GET http://registry.npmjs.org/local-tld
npm http 304 http://registry.npmjs.org/local-tld

> [email protected] preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall

++ id -u
+ '[' 4294967294 -eq 0 ']'
+ SUDO=sudo
+ sudo launchctl unload /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
Sorry, try again.

Whats wrong? Try install npm without sudo and i got this error.

⚡  npm install -g local-tld

> [email protected] preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall

++ id -u
+ '[' 501 -eq 0 ']'
+ SUDO=sudo
+ sudo launchctl unload /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
launchctl: Couldn't stat("/Library/LaunchDaemons/ie.hood.local-tld-firewall.plist"): No such file or directory
nothing found to unload
+ true
+ launchctl unload /Users/Cengkaruk/Library/LaunchAgents/ie.hood.local-tld-service.plist
launchctl: Couldn't stat("/Users/Cengkaruk/Library/LaunchAgents/ie.hood.local-tld-service.plist"): No such file or directory
nothing found to unload
+ true
+ sudo rm -f /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
+ rm -f /Users/Cengkaruk/Library/LaunchAgents/ie.hood.local-tld-service.plist
+ sudo rm -f /etc/resolver/dev

> [email protected] preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall

++ id -u
+ '[' 501 -eq 0 ']'
+ SUDO=sudo
+ sudo launchctl unload /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
launchctl: Couldn't stat("/Library/LaunchDaemons/ie.hood.local-tld-firewall.plist"): No such file or directory
nothing found to unload
+ true
+ launchctl unload /Users/Cengkaruk/Library/LaunchAgents/ie.hood.local-tld-service.plist
launchctl: Couldn't stat("/Users/Cengkaruk/Library/LaunchAgents/ie.hood.local-tld-service.plist"): No such file or directory
nothing found to unload
+ true
+ sudo rm -f /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
+ rm -f /Users/Cengkaruk/Library/LaunchAgents/ie.hood.local-tld-service.plist
+ sudo rm -f /etc/resolver/dev
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld'
npm ERR! error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/local-tld' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/local-tld' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

Connection refused

Okay, running on Lion, and got two problems.

First, it doesn't seem like I could get it to run properly. I'm using MAMP, running on port 80, where I have many sites.

I installed via npm install -g, as expected.

I tried adding one of them:
{
"80": {
"name": "app"
}
}

I'm unable to connect.

$ telnet app.dev 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host

What is worse, when I try to uninstall, I continue to get connection refused.

What's going on behind the scenes?

On a side note, is it possible to have multiple sites running on the same port (follow my MAMP setup)?

To clarify: I've tried uninstalling several times, but i'm not back to the way things were before install.

installing local-tld via npm as sudo gives errors

  • sudo npm install -g local-tld or npm install -g local-tld

ends up in a prompt that asks for my sudo passwd but doesn't recognize it.

All other sudo commands work and my passwd works on those

  • just as an A/B test I tried
    sudo npm install -g request
    that works

Even when I have just used sudo a few seconds before on another command which worked I still get asked for my passwd and it fails.

i.e. the issue is not with my passwd it seems to be with the local-tld install script.

==== long - see transcript below

npm install -g local-tld
npm http GET https://registry.npmjs.org/local-tld
npm http 304 https://registry.npmjs.org/local-tld

> [email protected] preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall

+ sudo launchctl unload /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
Password:
+ launchctl unload /Users/nitin/Library/LaunchAgents/ie.hood.local-tld-service.plist
+ sudo rm -f /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
+ rm -f /Users/nitin/Library/LaunchAgents/ie.hood.local-tld-service.plist
+ sudo rm -f /etc/resolver/dev

> [email protected] preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall

+ sudo launchctl unload /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
launchctl: Couldn't stat("/Library/LaunchDaemons/ie.hood.local-tld-firewall.plist"): No such file or directory
nothing found to unload
npm WARN continuing anyway [email protected] preuninstall: `./bin/local-tld-uninstall`
npm WARN continuing anyway `sh "-c" "./bin/local-tld-uninstall"` failed with 1
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld/.npmignore'
npm ERR! error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld/.npmignore']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/local-tld/.npmignore' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld/.npmignore'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld/.npmignore']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/local-tld/.npmignore' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "local-tld"
npm ERR! cwd /Users/nitin
npm ERR! node -v v0.10.3
npm ERR! npm -v 1.2.17
npm ERR! path /usr/local/lib/node_modules/local-tld/.npmignore
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/local-tld/.npmignore'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/nitin/npm-debug.log
npm ERR! not ok code 0
[00:58][nitin@nitinmacbookpro:~]$ sudo npm install -g local-tld
npm http GET https://registry.npmjs.org/local-tld
npm http 304 https://registry.npmjs.org/local-tld

> [email protected] preuninstall /usr/local/lib/node_modules/local-tld
> ./bin/local-tld-uninstall

+ sudo launchctl unload /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
sudo: 2 incorrect password attempts

actually I went to 3 more than once no difference

  • npm install local-tld works

gulp-connect + local-tld

I'm using gulp connect to serve, like so:

var port = 5000;
  connect.server({
    port: port,
    livereload: true
  });

Which works fine for accessing localhost:5000, however I'm adding local-tld.
So it registered itself:

if(process.platform == 'darwin') {
      ltld.add(pkg.name, port);
      gutil.log(pkg.name + '.dev:' + port)
}

And my ~/.local-tld.json is updated, however—http://PACKAGE_NAME.dev won't load assets, it only works when I access http://PACKAGE_NAME.dev:5000.

So it seems local-tld isn't routing the name to the port correctly, simply aliasing localhost. Any thought?

A workflow to serve static files

I want to serve a directory with static files. With pow I do:

➤ cat ~/Sites/n12v.com/public/index.html
Hello World!

With local-tld, am I expected to run something like python python -m SimpleHTTPServer first?

no longer supported?

Seems like most of the issues here are from 2013.

On my machine, local-tld no longer seems to work. OS X El Capital 10.11.4. It seems to recognize the name, but hte port mapping isn't working.

[jeffrey@smile idm]$ cat ~/.local-tld.json
{"9001":{"name":"idm.learnersguild"}}[jeffrey@smile idm]$ ping idm.learnersguild.dev
PING idm.learnersguild.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.062 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.053 ms
^C
--- idm.learnersguild.dev ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.053/0.058/0.062/0.004 ms
[jeffrey@smile idm]$ curl http://idm.learnersguild.dev
curl: (7) Failed to connect to idm.learnersguild.dev port 80: Connection refused
[jeffrey@smile idm]$ curl http://idm.learnersguild.dev:9001

    <!doctype html>
    <html>

[ ---- TEXT REMOVED FOR BREVITY ---- ]

    </html>
    [jeffrey@smile idm]$

Local-TLD blocks vhost resolution

Vhosts are no longer accessible when running a Hoodie app, and even after stopping the app. This helps:

sudo launchctl unload ~/Library/LaunchAgents/ie.hood.local-tld-service.plist
sudo ipfw flush

Direct access to localhost is only occasionally affected by Hoodie, but vhosts are always blocked.

doesn't seem to work when wifi is disabled?

(disclaimer: i'm not sure if this is the correct repo to report this bug)

in a fresh hoodie app if I have wifi turned off or if I'm not associated with an access point doing hoodie start opens a browser window to appname.dev but chrome shows Unable to connect to the Internet until I turn wifi on and connect to a network

add local-tld enable / disable convenience commands

basically all you need ist this:

  • disable: sudo ipfw flush

  • enable: sudo launchctl load -Fw /Library/LaunchDaemons/ie.hood.local-tld-firewall.plist
    we can make that convenience binaries, so you can do

    $ local-tld disable
    $ local-tld ensable

In order to avoid flushing unrelated firewall rules we can do something like this on disable:

sudo ipfw delete `sudo ipfw list | grep 127.0.0.1:5999 | awk '{print $1}'` #untested

Support custom `node` install locations

Currently etc/ie.hood.local-tld-firewall.plist hardcodes /usr/local/bin/node. We should support node installed anywhere, nvm is a use-case.

Here is a catch-22: Within the postinstall script, npm adds the realpath of the node binary into PATH, hence which node resolves to e.g. “/usr/local/Cellar/node/0.8.19/bin/node”. If we put that into the plist, it breaks on every node update, which would suck. We could parse which -a node and discard the first entry, but that’d break any expectation one would have from PATH.

Maybe @isaacs can advise?

/etc/hosts

the rules I have set up in /etc/hosts don't work after installing local-tld.

if I "sudo ipfw flush" then they all work again.

OS X 10.8.3

sadly local-tld has been nothing but problems for me. :(

Windows support

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.