Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for .xip.io domains

  • Loading branch information...
commit 4a1de8a7a1d33b7cd3684075003dcfd616c61791 1 parent 584a40d
@sstephenson sstephenson authored
View
16 MANUAL.md
@@ -131,6 +131,22 @@ domains with a particular Rack application. Create a symlink in
`~/.pow` named `default` and point it to the application of your
choice.
+#### Accessing Virtual Hosts From Other Computers ####
+
+Sometimes you need to access your Pow virtual hosts on another
+computer — for example, when testing your application on a
+mobile device.
+
+The `.dev` domain will only work on your development
+computer. However, you can use the special [`.xip.io`
+domain](http://xip.io/) to remotely access your Pow virtual hosts.
+
+Construct your xip.io domain by appending your application's name to
+your LAN IP address followed by `.xip.io`. For example, if your
+development computer's LAN IP address is `10.0.1.43`, you can visit
+`myapp.dev` from another computer on your local network using the URL
+`http://myapp.10.0.1.43.xip.io/`.
+
### Customizing Environment Variables ###
Pow lets you customize the environment in which worker processes
View
6 lib/configuration.js
@@ -73,6 +73,7 @@
this.domains = (_ref9 = typeof (_base = this.domains).split === "function" ? _base.split(",") : void 0) != null ? _ref9 : this.domains;
this.extDomains = (_ref10 = typeof (_base1 = this.extDomains).split === "function" ? _base1.split(",") : void 0) != null ? _ref10 : this.extDomains;
this.allDomains = this.domains.concat(this.extDomains);
+ this.allDomains.push(/\d+\.\d+\.\d+\.\d+\.xip\.io$/, /[0-9a-z]{1,7}\.xip\.io$/);
this.hostRoot = (_ref11 = env.POW_HOST_ROOT) != null ? _ref11 : libraryPath("Application Support", "Pow", "Hosts");
this.logRoot = (_ref12 = env.POW_LOG_ROOT) != null ? _ref12 : libraryPath("Logs", "Pow");
this.rvmPath = (_ref13 = env.POW_RVM_PATH) != null ? _ref13 : path.join(process.env.HOME, ".rvm/scripts/rvm");
@@ -185,8 +186,11 @@
};
getFilenamesForHost = function(host, domain) {
- var i, length, parts, _i, _results;
+ var i, length, parts, _i, _ref, _ref1, _results;
host = host.toLowerCase();
+ if (domain.test != null) {
+ domain = (_ref = (_ref1 = host.match(domain)) != null ? _ref1[0] : void 0) != null ? _ref : "";
+ }
if (host.slice(-domain.length - 1) === ("." + domain)) {
parts = host.slice(0, -domain.length - 1).split(".");
length = parts.length;
View
5 src/configuration.coffee
@@ -105,6 +105,9 @@ module.exports = class Configuration
@extDomains = @extDomains.split?(",") ? @extDomains
@allDomains = @domains.concat @extDomains
+ # Support *.xip.io top-level domains.
+ @allDomains.push /\d+\.\d+\.\d+\.\d+\.xip\.io$/, /[0-9a-z]{1,7}\.xip\.io$/
+
# `POW_HOST_ROOT`: path to the directory containing symlinks to
# applications that will be served by Pow. Defaults to
# `~/Library/Application Support/Pow/Hosts`.
@@ -213,6 +216,8 @@ libraryPath = (args...) ->
# `["basecamp"]`.
getFilenamesForHost = (host, domain) ->
host = host.toLowerCase()
+ domain = host.match(domain)?[0] ? "" if domain.test?
+
if host.slice(-domain.length - 1) is ".#{domain}"
parts = host.slice(0, -domain.length - 1).split "."
length = parts.length
View
32 test/test_configuration.coffee
@@ -90,6 +90,38 @@ module.exports = testCase
test.same fixturePath("configuration/directory"), conf.root
test.done()
+ "findHostConfiguration matches regex domains": (test) ->
+ configuration = createConfiguration POW_HOST_ROOT: fixturePath("configuration"), POW_DOMAINS: ["dev"], POW_EXT_DOMAINS: [/foo\d$/]
+ test.expect 2
+ configuration.findHostConfiguration "directory.foo3", (err, domain, conf) ->
+ test.ok domain.test?
+ test.same fixturePath("configuration/directory"), conf.root
+ test.done()
+
+ "findHostConfiguration matches xip.io domains": (test) ->
+ configuration = createConfiguration POW_HOST_ROOT: fixturePath("configuration")
+ matchHostToRoot = (host, fixtureRoot) -> (proceed) ->
+ configuration.findHostConfiguration host, (err, domain, conf) ->
+ if fixtureRoot
+ test.ok domain.test?
+ test.same { root: fixturePath(fixtureRoot) }, conf
+ else
+ test.ok !conf
+ proceed()
+
+ test.expect 16
+ async.parallel [
+ matchHostToRoot "directory.127.0.0.1.xip.io", "configuration/directory"
+ matchHostToRoot "directory.10.0.1.43.xip.io", "configuration/directory"
+ matchHostToRoot "directory.9zlhb.xip.io", "configuration/directory"
+ matchHostToRoot "directory.bxjy16.xip.io", "configuration/directory"
+ matchHostToRoot "sub.directory.9zlhb.xip.io", "configuration/directory"
+ matchHostToRoot "www.directory.9zlhb.xip.io", "configuration/www.directory"
+ matchHostToRoot "www.directory.127.0.0.1.xip.io", "configuration/www.directory"
+ matchHostToRoot "127.0.0.1.xip.io"
+ matchHostToRoot "nonexistent.127.0.0.1.xip.io"
+ ], test.done
+
"getLogger returns the same logger instance": (test) ->
configuration = createConfiguration()
logger = configuration.getLogger "test"
Please sign in to comment.
Something went wrong with that request. Please try again.