diff --git a/.github/workflows/ci.yml b/.github/workflows/build-and-test.yml
similarity index 51%
rename from .github/workflows/ci.yml
rename to .github/workflows/build-and-test.yml
index 36581a8..166c9ac 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/build-and-test.yml
@@ -1,4 +1,4 @@
-name: strava-heatmap-proxy-ci
+name: build-and-test
on: [ "pull_request" ]
@@ -10,21 +10,16 @@ jobs:
- uses: actions/setup-go@v6
with:
- go-version-file: 'go.mod'
+ go-version-file: "strava-heatmap-proxy/go.mod"
- - name: Check gofmt
- run: |
- UNFORMATTED=$(gofmt -l .)
- if [ -n "$UNFORMATTED" ]; then
- echo -e "The following files are not properly formatted:\n${UNFORMATTED}"
- exit 1
- fi
+ - name: Check code format
+ run: make -C strava-heatmap-proxy formatcheck
- uses: docker/setup-buildx-action@v3
- name: Build image
uses: docker/build-push-action@v6
with:
- context: .
+ context: strava-heatmap-proxy/
platforms: linux/amd64
push: false
diff --git a/.github/workflows/cd.yml b/.github/workflows/deploy.yml
similarity index 63%
rename from .github/workflows/cd.yml
rename to .github/workflows/deploy.yml
index 6a29ad8..bef0532 100644
--- a/.github/workflows/cd.yml
+++ b/.github/workflows/deploy.yml
@@ -1,14 +1,11 @@
-name: strava-heatmap-proxy-cd
+name: deploy
on:
push:
branches: [ "main" ]
paths:
- ".github/workflows/**"
- - "Dockerfile"
- - "go.mod"
- - "go.sum"
- - "strava-heatmap-proxy.go"
+ - "strava-heatmap-proxy/**"
jobs:
cd:
@@ -27,13 +24,9 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v6
with:
- context: .
+ context: strava-heatmap-proxy/
platforms: linux/amd64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/strava-heatmap-proxy:latest
${{ secrets.DOCKERHUB_USERNAME }}/strava-heatmap-proxy:${{ github.sha }}
- cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/strava-heatmap-proxy:buildcache
- cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/strava-heatmap-proxy:buildcache,mode=max
- provenance: false
- sbom: false
diff --git a/.gitignore b/.gitignore
index fdb260b..6063600 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,4 +21,4 @@ build/
TODO
strava-cookie-exporter.zip
-strava-heatmap-proxy
+strava-heatmap-proxy/strava-heatmap-proxy
diff --git a/Makefile b/Makefile
index 1666973..4336362 100644
--- a/Makefile
+++ b/Makefile
@@ -1,34 +1,6 @@
-SERVICE_NAME := strava-heatmap-proxy
-EXTENSION_NAME := strava-cookie-exporter
+SUBDIRS := strava-cookie-exporter strava-heatmap-proxy
-OUTPUT := \
- $(SERVICE_NAME) \
- $(EXTENSION_NAME).zip
+.PHONY: $(SUBDIRS) all clean
-.PHONY: all clean
-
-all: $(OUTPUT)
-
-$(SERVICE_NAME):
- go build $@.go
-
-$(EXTENSION_NAME).zip:
- 7z a $@ ./$(EXTENSION_NAME)/*
-
-clean:
- rm -f $(OUTPUT)
-
-install:
- GOPATH=$(HOME)/.local go install $(SERVICE_NAME).go
- mkdir -p $(HOME)/.config/systemd/user/
- cp $(SERVICE_NAME).service $(HOME)/.config/systemd/user/
- systemctl --user daemon-reload
- systemctl --user start $(SERVICE_NAME)
- systemctl --user enable $(SERVICE_NAME)
-
-uninstall:
- rm -f $(addprefix $(HOME)/.local/bin/, $(SERVICE_NAME))
- rm $(HOME)/.config/systemd/user/$(SERVICE_NAME).service
- systemctl --user disable $(SERVICE_NAME)
- systemctl --user stop $(SERVICE_NAME)
- systemctl --user daemon-reload
+all clean:
+ $(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) $@;)
diff --git a/README.md b/README.md
index 566588f..6f35147 100644
--- a/README.md
+++ b/README.md
@@ -6,35 +6,12 @@ To do so, you need the following two pieces:
1. The [strava-cookie-exporter](#export-cookies) browser extension to export the necessary cookies as json file
1. The [strava-heatmap-proxy](#run-the-proxy) server which adds the necessary cookies to your requests before redirecting them to Strava
-Note: [Previous versions](https://github.com/patrickziegler/strava-heatmap-proxy/tree/v1) of this repository were able to login to Strava automatically when running the proxy server.
-Due to recent changes on Strava side this is not possible anymore and we need to extract (at least) a valid session identifier via the browser extension.
-The proxy will then automatically refresh CloudFront tokens in case they have expired.
+> [!NOTE]
+> [Previous versions](https://github.com/patrickziegler/strava-heatmap-proxy/tree/v1) of this repository were able to login to Strava automatically when running the proxy server.
+> Due to recent changes on Strava side this is not possible anymore and we need to extract (at least) a valid session identifier via the browser extension.
+> The proxy will then automatically refresh CloudFront tokens in case they have expired.
-## :hammer_and_wrench: Build and Install
-
-With [git](https://git-scm.com/downloads), [golang](https://go.dev/) and [make](https://www.gnu.org/software/make/) available on your system, the following steps are sufficient to build and install `strava-heatmap-proxy` to the given path `INSTALL_PREFIX`:
-
-```sh
-git clone https://github.com/patrickziegler/strava-heatmap-proxy
-cd strava-heatmap-proxy
-INSTALL_PREFIX=~/.local/bin make install
-```
-
-In case you don't have these tools available, the `Dockerfile` allows to build a containerized version of the proxy server as well:
-
-```sh
-docker build -t strava-heatmap-proxy .
-docker run --rm -p 8080:8080 -v ~/.config/strava-heatmap-proxy:/config:ro strava-heatmap-proxy
-```
-
-Alternatively, you can download and execute a pre-built [container image](https://hub.docker.com/repository/docker/patrickziegler/strava-heatmap-proxy) with the following command:
-
-```sh
-docker run --rm -p 8080:8080 -v ~/.config/strava-heatmap-proxy:/config:ro docker.io/patrickziegler/strava-heatmap-proxy:latest
-```
-
-
-## :world_map: Usage
+## Usage
### Export cookies
@@ -46,16 +23,21 @@ With this extension installed, you can:
The exported file is needed for running [strava-heatmap-proxy](#run-the-proxy).
+Even though the exported cookies have an expiration period of 24 hours, you'll like only need to export them once because the proxy can automatically refresh expired cookies as long as the session is valid (the exact duration of that is unkown right now, but it seems to be several months at least).
+
### Run the proxy
-Running the tool `strava-heatmap-proxy` from your terminal will set up a local proxy server for `https://content-a.strava.com/`.
-Every request to `http://localhost:8080/` will then be extended with session cookies before being forwarded to Strava.
-You can configure different target URLs or port numbers via the `--target` or `--port` options.
+You can use the [prebuilt Docker image](https://hub.docker.com/repository/docker/patrickziegler/strava-heatmap-proxy) for running a local instance of the proxy server in your terminal:
-By default, the necessary cookies are expected to be found in the file `${HOME}/.config/strava-heatmap-proxy/strava-cookies.json` (should be manually created with the `strava-cookie-exporter` extension).
-You can configure different locations of that file via the `--cookies` option.
+```sh
+LOCAL_PORT=8080
+docker run --rm -p ${LOCAL_PORT}:8080 -v ${HOME}/.config/strava-heatmap-proxy:/home/nonroot/.config/strava-heatmap-proxy:ro docker.io/patrickziegler/strava-heatmap-proxy:latest
+```
-The CloudFront cookies have an expiration period of 24 hours, but you don't need to recreate the `strava-cookies.json` file all the time because `strava-heatmap-proxy` can automatically refresh expired cookies as long as the session is valid (the exact duration of that is unkown right now, but it seems to be several weeks at least).
+This will set up a local proxy server for `https://content-a.strava.com/`.
+Every request to `http://localhost:8080/` will then be extended with session cookies before being forwarded to Strava.
+
+By default, the necessary cookies are expected to be found in the file `${HOME}/.config/strava-heatmap-proxy/strava-cookies.json` (as created with the [strava-cookie-exporter](#export-cookies) extension).
### Configure your TMS client
@@ -67,7 +49,7 @@ To use this with your GIS software of choice, just define a simple [TMS](https:/
5
16
- http://localhost:8080/identified/globalheat/all/bluered/%1/%2/%3.png?v=19
+ http://localhost:8080/identified/globalheat/all/bluered/{z}/{x}/{y}.png?v=19
```
@@ -76,20 +58,16 @@ The `ServerUrl` can hold other elements than `all` and `bluered`. If you want to
### Advanced configuration for web clients
-Web clients like [gpx.studio](https://gpx.studio/) need to be whitelisted via the `--allow-origins` option.
+Web clients like [gpx.studio](https://gpx.studio/) need to be whitelisted via the `--allow-origins '["https://gpx.studio"]'` option.
Otherwise the browser would reject the responses due to a violation of the [same-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy).
-```sh
-strava-heatmap-proxy --allow-origins '["https://gpx.studio"]' --port 8080
-```
-
-With that in place, you can add the custom layer `http://localhost:8080/identified/globalheat/all/bluered/{z}/{x}/{y}.png?v=19` for accessing the heatmap.
+With the option in place, you can add the custom layer `http://localhost:8080/identified/globalheat/all/bluered/{z}/{x}/{y}.png?v=19` for accessing the heatmap.
## Screenshot
-And this is how the result might look like in [QMapShack](https://github.com/Maproom/qmapshack/wiki):
+This is how the result might look like in [QMapShack](https://github.com/Maproom/qmapshack/wiki):
-
+
## References
diff --git a/go.mod b/go.mod
deleted file mode 100644
index e087c20..0000000
--- a/go.mod
+++ /dev/null
@@ -1,3 +0,0 @@
-module github.com/patrickziegler/strava-heatmap-proxy
-
-go 1.24
diff --git a/strava-cookie-exporter/Makefile b/strava-cookie-exporter/Makefile
new file mode 100644
index 0000000..9b1fc70
--- /dev/null
+++ b/strava-cookie-exporter/Makefile
@@ -0,0 +1,14 @@
+EXTENSION_NAME := strava-cookie-exporter
+
+OUTPUT := \
+ $(EXTENSION_NAME).zip
+
+.PHONY: all clean
+
+all: $(OUTPUT)
+
+$(EXTENSION_NAME).zip:
+ 7z a $@ ./* -x!Makefile
+
+clean:
+ rm -f $(OUTPUT)
diff --git a/Dockerfile b/strava-heatmap-proxy/Dockerfile
similarity index 50%
rename from Dockerfile
rename to strava-heatmap-proxy/Dockerfile
index b7a5358..ead1d3b 100644
--- a/Dockerfile
+++ b/strava-heatmap-proxy/Dockerfile
@@ -2,9 +2,9 @@
# --- Build stage ---
FROM golang:1.24 AS build
+COPY ./ /src
WORKDIR /src
-# Build the proxy binary from the module ROOT (no cmd/... suffix)
-RUN CGO_ENABLED=0 go install github.com/patrickziegler/strava-heatmap-proxy@latest
+RUN CGO_ENABLED=0 go install ./cmd/strava-heatmap-proxy
# --- Runtime stage ---
FROM gcr.io/distroless/base-debian13:nonroot
@@ -12,6 +12,5 @@ WORKDIR /app
COPY --from=build /go/bin/strava-heatmap-proxy ./
EXPOSE 8080
USER nonroot:nonroot
-# Looks for cookies at /config/strava-cookies.json by default (mount it read-only)
+
ENTRYPOINT ["/app/strava-heatmap-proxy"]
-CMD ["--port","8080","--cookies","/config/strava-cookies.json"]
diff --git a/strava-heatmap-proxy/Makefile b/strava-heatmap-proxy/Makefile
new file mode 100644
index 0000000..b64f553
--- /dev/null
+++ b/strava-heatmap-proxy/Makefile
@@ -0,0 +1,42 @@
+SERVICE_NAME := strava-heatmap-proxy
+LOCAL_PORT := 9192
+
+OUTPUT := \
+ $(SERVICE_NAME)
+
+.PHONY: all clean install uninstall formatcheck container
+
+all: $(OUTPUT)
+
+$(SERVICE_NAME):
+ go build ./cmd/$@
+
+clean:
+ rm -f $(OUTPUT)
+
+install:
+ GOPATH=$(HOME)/.local go install ./cmd/$(SERVICE_NAME)
+ mkdir -p $(HOME)/.config/systemd/user/
+ cp ./systemd/$(SERVICE_NAME).service $(HOME)/.config/systemd/user/
+ systemctl --user daemon-reload
+ systemctl --user restart $(SERVICE_NAME)
+ systemctl --user enable $(SERVICE_NAME)
+
+uninstall:
+ rm -f $(addprefix $(HOME)/.local/bin/, $(SERVICE_NAME))
+ rm -f $(HOME)/.config/systemd/user/$(SERVICE_NAME).service
+ systemctl --user disable $(SERVICE_NAME) || true
+ systemctl --user stop $(SERVICE_NAME) || true
+ systemctl --user daemon-reload
+
+formatcheck:
+ UNFORMATTED=$$(gofmt -l .) && \
+ if [ -n "$$UNFORMATTED" ]; then \
+ echo "The following files are not properly formatted:"; \
+ echo "$$UNFORMATTED"; \
+ exit 1; \
+ fi
+
+container:
+ docker build -t $(SERVICE_NAME) .
+ docker run --rm -p $(LOCAL_PORT):8080 -v $(HOME)/.config/$(SERVICE_NAME):/home/nonroot/.config/$(SERVICE_NAME):ro $(SERVICE_NAME) || true
diff --git a/strava-heatmap-proxy.go b/strava-heatmap-proxy/cmd/strava-heatmap-proxy/main.go
similarity index 100%
rename from strava-heatmap-proxy.go
rename to strava-heatmap-proxy/cmd/strava-heatmap-proxy/main.go
diff --git a/strava-heatmap-proxy/go.mod b/strava-heatmap-proxy/go.mod
new file mode 100644
index 0000000..b26de23
--- /dev/null
+++ b/strava-heatmap-proxy/go.mod
@@ -0,0 +1,3 @@
+module github.com/patrickziegler/strava-heatmap-proxy/strava-heatmap-proxy
+
+go 1.24
diff --git a/go.sum b/strava-heatmap-proxy/go.sum
similarity index 100%
rename from go.sum
rename to strava-heatmap-proxy/go.sum
diff --git a/strava-heatmap-proxy.service b/strava-heatmap-proxy/systemd/strava-heatmap-proxy.service
similarity index 99%
rename from strava-heatmap-proxy.service
rename to strava-heatmap-proxy/systemd/strava-heatmap-proxy.service
index 5d825a1..3688f04 100644
--- a/strava-heatmap-proxy.service
+++ b/strava-heatmap-proxy/systemd/strava-heatmap-proxy.service
@@ -9,6 +9,5 @@ ExecStart=%h/.local/bin/strava-heatmap-proxy --port ${STRAVA_HEATMAP_PROXY_PORT}
Restart=on-failure
RestartSec=5
-
[Install]
WantedBy=default.target