diff options
author | lassulus <lassulus@googlemail.com> | 2014-01-07 20:28:20 +0100 |
---|---|---|
committer | lassulus <lassulus@googlemail.com> | 2014-01-07 20:28:20 +0100 |
commit | 452b234c61a2c4ba8d2c4af00e0c2cdc0007dced (patch) | |
tree | 278f8566bddd8bec1e81c9423e4b057c98cd87d7 /go | |
parent | 9d91f297622e45a79d6ed752615e635eccdc0707 (diff) | |
parent | e7124e30ed9e6833670a85d42a08650c7963eb35 (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'go')
-rw-r--r-- | go/README.markdown | 12 | ||||
-rw-r--r-- | go/etc/conf.d/go.env | 2 | ||||
-rw-r--r-- | go/index.js | 18 |
3 files changed, 4 insertions, 28 deletions
diff --git a/go/README.markdown b/go/README.markdown index 2d4ba909..22b7c642 100644 --- a/go/README.markdown +++ b/go/README.markdown @@ -12,30 +12,24 @@ ## run service - HOSTN=go PORT=80 URI_PREFIX=http://go node . + PORT=80 node . - if you omit `HOSTN`, then relative shortened uris will be generated. if you omit `PORT`, then it's `1337`. - if you omit `URI_PREFIX`, then it will be generated from `HOSTN` änd `PORT`. there's also the possibility to change the Redis key prefix which defaults to `go:` with REDIS_KEY_PREFIX=foobarmyprefix/ - to generate slightly more informative shortened uris set - - NOT_SO_SHORT=true - ## add uri - curl -F uri=https://mywaytoolonguri http://go + curl -F uri=https://mywaytoolonguri http://localhost:1337 this will give you a shortened uri. ## resolve uri - curl -L http://go/1 + curl -L http://localhost:1337/1 ## clear database diff --git a/go/etc/conf.d/go.env b/go/etc/conf.d/go.env index 477c7eeb..6045deac 100644 --- a/go/etc/conf.d/go.env +++ b/go/etc/conf.d/go.env @@ -1,4 +1,2 @@ -HOSTN=go PORT=1337 -URI_PREFIX=http://go REDIS_KEY_PREFIX=go: diff --git a/go/index.js b/go/index.js index 3bac2f7b..e9b551c0 100644 --- a/go/index.js +++ b/go/index.js @@ -1,24 +1,12 @@ // configuration -var hostname = process.env.HOSTN; var httpPort = process.env.PORT; -var uriPrefix = process.env.URI_PREFIX; var redisPrefix = process.env.REDIS_KEY_PREFIX; -var appendDomainToUri = process.env.NOT_SO_SHORT === 'true'; // automatic configuration if (!httpPort) { httpPort = 1337; } -if (!uriPrefix) { - uriPrefix = ''; - if (hostname) { - uriPrefix += 'http://' + hostname; - if (httpPort != 80) { - uriPrefix += ':' + httpPort; - } - } -} if (!redisPrefix) { redisPrefix = 'go:'; } @@ -73,7 +61,7 @@ function create (req, res) { var uri = fields.uri; // TODO check uri(?) var shortPath = '/' + reply; - var shortUri = uriPrefix + shortPath; + var shortUri = 'http://' + req.headers.host + shortPath; var key = redisPrefix + shortPath; redisClient.set(key, uri, function (error) { @@ -81,10 +69,6 @@ function create (req, res) { return internalError(err, req, res); } - if (appendDomainToUri) { - shortUri += '#' + url.parse(uri).host - } - res.writeHead(200, { 'content-type': 'text/plain' }); return res.end(shortUri + '\r\n'); }); |