From d0d2c2e64f4a6f742270a80dd5e71d3f54409796 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Thu, 15 Jul 2021 23:08:51 +0200 Subject: [PATCH] Add path patch to dockerfile PR is open for a month now, so I've added it directly to the docker image to stop waiting. https://code.rocketnine.space/tslocum/twins/pulls/10 --- Dockerfile | 14 +++++++-- path-10.patch | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 path-10.patch diff --git a/Dockerfile b/Dockerfile index d618265..03fa134 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,17 @@ # Build FROM golang:1.16-alpine AS builder -RUN apk add --no-cache openssl -RUN go get -v code.rocketnine.space/tslocum/twins +RUN apk add --no-cache openssl patch git +WORKDIR /build COPY ./localhost.cnf /build/localhost.cnf +RUN git clone https://code.rocketnine.space/tslocum/twins.git + +# Apply a needed patch +COPY ./path-10.patch /build/path-10.patch +RUN cd /build/twins && patch /build/path-10.patch + +RUN cd /build/twins && go build + RUN openssl req \ -x509 \ -out /build/localhost.crt \ @@ -20,7 +28,7 @@ RUN openssl req \ # Compress FROM gruebel/upx:latest as upx -COPY --from=builder /go/bin/twins /app.org +COPY --from=builder /build/twins/twins /app.org RUN upx --best --lzma -o /app /app.org # Final image diff --git a/path-10.patch b/path-10.patch new file mode 100644 index 0000000..53d7a14 --- /dev/null +++ b/path-10.patch @@ -0,0 +1,78 @@ +From bd0555069ede209f482a524a9a18fdc9a3f35183 Mon Sep 17 00:00:00 2001 +From: Aaron Fischer +Date: Thu, 3 Jun 2021 23:47:46 +0200 +Subject: [PATCH 1/2] Strip path from root + +If there is a path (the URL path) specified under paths in the +configuration, which points to a root (a physical folder on the +filesystem), this path should not be attached to the root. This fix will +do that. It strips the path from the root. + +Example configuration: + +hosts: + localhost: + paths: + - + path: /a + root: public/aroot + - + path: / + root: public + +Filesystem: ++ public + + index.gmi + + aroot + + index.gmi +--- + serve_https.go | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/serve_https.go b/serve_https.go +index e227064..6ab3a41 100644 +--- a/serve_https.go ++++ b/serve_https.go +@@ -80,7 +80,9 @@ func serveHTTPS(w http.ResponseWriter, r *http.Request) (int, int64, string) { + root += "/" + } + +- requestSplit := strings.Split(r.URL.Path, "/") ++ // We remove the the path (specified in the config file) from the actual URL, so ++ // it will not prefixed two times to the root. ++ requestSplit := strings.Split(r.URL.Path[len(serve.Path)-1:], "/") + + if !serve.SymLinks { + for i := 1; i < len(requestSplit); i++ { +-- +2.32.0 + + +From 2257e0bcceb8dd2d3f471d679153cd08de4a7ef0 Mon Sep 17 00:00:00 2001 +From: Aaron Fischer +Date: Mon, 7 Jun 2021 23:20:24 +0200 +Subject: [PATCH 2/2] Add some clarification for the paths arrangement + +--- + CONFIGURATION.md | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/CONFIGURATION.md b/CONFIGURATION.md +index 46c1987..471ca14 100644 +--- a/CONFIGURATION.md ++++ b/CONFIGURATION.md +@@ -90,6 +90,11 @@ See [PROPOSALS.md](https://code.rocketnine.space/tslocum/twins/src/branch/master + + ### Path + ++Specify any number of paths, which will be checked against the request. The ++first match will be used to build the response. So keep in mind that the ++first path should be the most specific one and the last should be the least ++specific one, like `/`. ++ + #### Resources + + One resource must be defined for each path. +-- +2.32.0 +