summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2014-01-06 02:14:51 +0100
committertv <tv@nomic.retiolum>2014-01-06 02:14:51 +0100
commit95a3ef4804ccd253f246923d3dfc78d983027fdb (patch)
tree3af6c6be8edb1c8e86ee4a822d19597cf0c36037
parentc7ab5042fef55b71baf6bb637cb6033b25007845 (diff)
go: make host in shortened uri available
-rw-r--r--go/README.markdown4
-rw-r--r--go/index.js8
2 files changed, 11 insertions, 1 deletions
diff --git a/go/README.markdown b/go/README.markdown
index 87e0541e..2d4ba909 100644
--- a/go/README.markdown
+++ b/go/README.markdown
@@ -23,6 +23,10 @@
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
diff --git a/go/index.js b/go/index.js
index 7f1e6a07..3bac2f7b 100644
--- a/go/index.js
+++ b/go/index.js
@@ -3,6 +3,7 @@ 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
@@ -25,6 +26,7 @@ if (!redisPrefix) {
// load libraries
var http = require('http');
+var url = require('url');
var formidable = require('formidable');
var redis = require('redis');
@@ -79,6 +81,10 @@ 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');
});
@@ -87,7 +93,7 @@ function create (req, res) {
}
function retrieve (req, res) {
- var key = redisPrefix + req.url;
+ var key = redisPrefix + url.parse(req.url).path;
redisClient.get(key, function (error, reply) {
if (error) {
return internalError(err, req, res);