summaryrefslogtreecommitdiffstats
path: root/go
diff options
context:
space:
mode:
Diffstat (limited to 'go')
-rw-r--r--go/README.markdown12
-rw-r--r--go/etc/conf.d/go.env2
-rw-r--r--go/index.js18
-rwxr-xr-xgo/t/docker/docker_deploy.sh10
-rw-r--r--go/t/docker/dockertest/deploy9
5 files changed, 13 insertions, 38 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');
});
diff --git a/go/t/docker/docker_deploy.sh b/go/t/docker/docker_deploy.sh
index 7ed0de58..1b4a433c 100755
--- a/go/t/docker/docker_deploy.sh
+++ b/go/t/docker/docker_deploy.sh
@@ -1,13 +1,13 @@
#!/bin/bash
cd $(dirname $(readlink -f $0))
-set -euf
+set -xeuf
rnd_port=$(shuf -i 2000-65000 -n 1)
docker_id=$(docker run -p $rnd_port:80 -d -v /krebs/go/t/docker/../../../:/krebs ubuntu /bin/bash /krebs/go/t/docker/dockertest/deploy)
#docker run -p $rnd_port:80 -v /krebs/go/t/docker/../../../:/krebs ubuntu /bin/bash /krebs/go/t/docker/dockertest/deploy
echo $docker_id on $rnd_port
trap "docker stop $docker_id;docker rm $docker_id" INT TERM EXIT QUIT
i=0
-max_wait=20
+max_wait=30
echo "waiting for install (takes about 3 minutes)"
sleep 240
while ! curl -s localhost:$rnd_port >/dev/null ;do
@@ -15,6 +15,6 @@ while ! curl -s localhost:$rnd_port >/dev/null ;do
test $i -gt $max_wait && echo "timeout for installation reached, bailing out" && exit 1
echo "http port not yet reachable ($i of $max_wait). waiting"
sleep 10
-done
-short_uri=$(curl -F "uri=aids.balls" localhost:$rnd_port)
-curl $short_uri -v | grep location: | grep aids.balls
+done
+short_uri=$(curl -F "uri=aids.balls" localhost:$rnd_port| sed 's/\r$//')
+curl $short_uri -v 2>&1 | grep location: | grep aids.balls
diff --git a/go/t/docker/dockertest/deploy b/go/t/docker/dockertest/deploy
index f3c45277..399f469c 100644
--- a/go/t/docker/dockertest/deploy
+++ b/go/t/docker/dockertest/deploy
@@ -1,11 +1,10 @@
#!/bin/sh
echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
apt-get update
-sudo apt-get update
-sudo apt-get install -y python-software-properties python g++ make
-sudo add-apt-repository -y ppa:chris-lea/node.js
-sudo apt-get update
-sudo apt-get -y install nodejs redis-server
+apt-get install -y python-software-properties python g++ make
+add-apt-repository -y ppa:chris-lea/node.js
+apt-get update
+apt-get -y install nodejs redis-server
npm config set registry http://registry.npmjs.org/
cd /krebs/go
npm install