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
This commit is contained in:
Aaron Fischer 2021-07-15 23:08:51 +02:00
parent 856d524707
commit d0d2c2e64f
2 changed files with 89 additions and 3 deletions

View file

@ -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

78
path-10.patch Normal file
View file

@ -0,0 +1,78 @@
From bd0555069ede209f482a524a9a18fdc9a3f35183 Mon Sep 17 00:00:00 2001
From: Aaron Fischer <mail@aaron-fischer.net>
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 <mail@aaron-fischer.net>
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