diff --git a/Dockerfile b/Dockerfile
index 76b894b..68233ab 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,8 +11,13 @@ RUN apt-get update && apt-get install -y \
wget -q -O $pkgname $pkgurl && dpkg -i $pkgname && rm $pkgname
RUN luarocks install sitegen
-RUN luarocks install busted
-RUN luarocks install luajit-curl
+
+# needed for sitegen watcher
RUN luarocks install inotify INOTIFY_INCDIR=/usr/include/x86_64-linux-gnu/
+# needed for testing
+RUN luarocks install busted
+RUN luarocks install luajit-curl
+RUN luarocks install luasocket # needed for testing nginx reverse proxy
+
CMD ["sh", "-c", "openresty -p `pwd` -g 'daemon off;'"]
diff --git a/app.ini b/app.ini
index a8fb316..c06ea4d 100644
--- a/app.ini
+++ b/app.ini
@@ -21,12 +21,12 @@ ROOT = /var/lib/gitea/data/gitea-repositories
[server]
; SSH_DOMAIN = localhost
-SSH_DOMAIN = git.miti.sh
+; SSH_DOMAIN = git.miti.sh
; DOMAIN = localhost
-DOMAIN = git.miti.sh
-HTTP_PORT = 3000
+; DOMAIN = git.miti.sh
+; HTTP_PORT = 3000
; ROOT_URL = http://localhost:3000/
-ROOT_URL = https://git.miti.sh
+ROOT_URL = https://git.miti.sh:3000
APP_DATA_PATH = /var/lib/gitea/data
DISABLE_SSH = false
SSH_PORT = 22
diff --git a/conf/nginx.conf b/conf/nginx.conf
index c94c2a9..43d27a9 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -37,7 +37,7 @@ http {
location / {
client_max_body_size 1024M;
- proxy_pass http://localhost:3000;
+ proxy_pass http://unix:/run/gitea/gitea.socket;
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
diff --git a/spec/routes_spec.moon b/spec/routes_spec.moon
index 2f87fac..54faf94 100644
--- a/spec/routes_spec.moon
+++ b/spec/routes_spec.moon
@@ -104,12 +104,14 @@ describe "http://miti.sh/posts", ->
assert.same request\body!\match("
(.*)"), "miti.sh ยท Posts"
describe "http://git.miti.sh", ->
- it "doesn't find it?", ->
+ it "reverse proxies request to unix socket", ->
+ os.execute "mkdir /run/gitea"
+ p = io.popen "luajit unixstreamsrvr.lua"
+ os.execute("sleep 1")
+ os.execute("chown -R nobody /run/gitea")
+
request = req "http://git.miti.sh"
- require("moon").p request\body!
- require("moon").p request\header!
- -- assert.same request\statusCode!, 404
- -- assert.same request\statusMessage!, "Not Found"
+ assert.is_not_nil p\read"*a"\match "Host: git.miti.sh"
describe "http://apps.miti.sh", ->
it "doesn't find it", ->
diff --git a/test.sh b/test.sh
index b1cc03a..aad5089 100755
--- a/test.sh
+++ b/test.sh
@@ -1,20 +1,19 @@
#!/usr/bin/env bash
-# echo "hello"
-# curl http://webdevcat.me:8080
image=miti.sh
+loopback=127.0.0.1
echo "Starting test container..."
# Make sure to create 'no-internet' network, if it doesn't already exist:
# $ docker network create --internal no-internet
container_id=$(docker run --rm -d -v $(pwd):/opt/app --network no-internet \
- --add-host=miti.sh=127.0.0.1 \
- --add-host=apps.miti.sh=127.0.0.1 \
- --add-host=git.miti.sh=127.0.0.1 \
- --add-host=webdevcat.me=127.0.0.1 \
- --add-host=apps.webdevcat.me=127.0.0.1 \
- --add-host=git.webdevcat.me=127.0.0.1 \
+ --add-host=miti.sh=$loopback \
+ --add-host=git.miti.sh=$loopback \
+ --add-host=apps.miti.sh=$loopback \
+ --add-host=webdevcat.me=$loopback \
+ --add-host=git.webdevcat.me=$loopback \
+ --add-host=apps.webdevcat.me=$loopback \
$image)
echo "Test container started"
@@ -23,20 +22,6 @@ echo "Test container started"
# docker exec -t $container_id cat /opt/app/logs/error.log
docker exec -t $container_id busted
-# echo "redirects webdevcat.me to miti.sh"
-
-# response=$(docker exec -t $container_id curl -so /dev/null \
-# -w "%{http_code} %{redirect_url}" http://webdevcat.me:8080)
-
-# expected="301 http://miti.sh:8080/"
-
-# if [[ $response != $expected ]]; then
-# echo "TEST FAILED"
-# printf "expected: $expected\ngot: $response\n"
-# else
-# echo "TEST PASSED"
-# fi
-
echo "Stopping test container"
docker exec $container_id openresty -p /opt/app -s stop
diff --git a/unixstreamsrvr.lua b/unixstreamsrvr.lua
new file mode 100644
index 0000000..407d17d
--- /dev/null
+++ b/unixstreamsrvr.lua
@@ -0,0 +1,12 @@
+ socket = require"socket"
+ socket.unix = require"socket.unix"
+ u = assert(socket.unix.stream())
+ assert(u:bind("/run/gitea/gitea.socket"))
+ assert(u:listen())
+ c = assert(u:accept())
+
+ m = assert(c:receive())
+ repeat
+ print(m)
+ m = assert(c:receive())
+ until m == ""