Commit Graph
22 Commits
Author SHA1 Message Date
Philipp 4e5c0fd401 fix(docker): serve precompressed static assets (#583)
Generate gzip sidecars for JavaScript, CSS, and WebAssembly assets during the image build. Serve them through nginx when clients accept gzip, including proxied requests, while preserving uncompressed fallback and runtime HTML base-path rewriting.
2026-10-03 21:03:22 +02:00
0a1f5dc450 feat(docker): serve the app from any subpath with a runtime BASE_URL (#565)
* feat(docker): serve the app from any subpath with a runtime BASE_URL

BASE_URL was a build argument, so hosting under a subfolder meant building
your own image (or pulling the separate baseurl-it-tools tag, which is only
ever right for /it-tools/). Make it a runtime setting instead, so the regular
image works anywhere:

    docker run -e BASE_URL=/it-tools/ ghcr.io/sharevb/it-tools:latest

The build is now path-agnostic. Vite's base is relative, so hashed assets and
lazy chunks resolve against the chunk that imports them, and the single
absolute anchor left in the output is a `<base href="/">` injected into
index.html. nginx rewrites that one tag per request (sub_filter) from the
normalised BASE_URL, and the app reads its base back from it at runtime
(src/utils/base-url.ts) for the router and for every URL it builds into
public/ -- import.meta.env.BASE_URL is meaningless in a relative build.

Also handled:

- both reverse-proxy styles: the prefix may reach the container (stripped by
  the rewrite) or be stripped by the proxy first (nothing to do). The assets
  location matches with or without it, so a missing chunk is still a 404
  rather than the SPA shell.
- `/it-tools` redirects to `/it-tools/`, with a relative Location so the
  scheme of the proxy hop does not leak into it.
- the PWA: manifest URLs are relative to the manifest, workbox precache
  entries relative to the service worker, and the worker is registered
  against the runtime base rather than the build-time one.
- BASE_URL is normalised (`it-tools`, `/it-tools`, `/it-tools/` all work) and
  rejected if it is not a plain path, since it lands in an HTML attribute and
  in an nginx regex.

Defaults are unchanged: with BASE_URL unset the rendered config and the
served page are what they were, except that index.html loses ETag/Last-Modified
to sub_filter. On a read-only filesystem the template cannot be re-rendered,
so BASE_URL is ignored there and the container now says so, like it already
had to for PORT.

Building with --build-arg BASE_URL still works but only moves the image
default; the baseurl-it-tools tag is now just latest with that default.

Closes sharevb/it-tools#403

* fix(docker): restore the PWA update reload, escape BASE_URL in the nginx regexes

Follow-up from review of the runtime BASE_URL change.

- registerSW() in autoUpdate mode reloaded the page when a newly deployed
  worker took over (workbox-window's `activated` handler); hand-rolling the
  registration dropped that, so a tab kept running the previous bundle until
  it navigated. Reimplemented on `controllerchange`, guarded so a first
  install -- which also claims the page -- does not reload. Verified by
  counting document loads across an install and a simulated deploy: 1 load on
  first visit, exactly 1 reload when a new worker takes over.
- The comment justifying the hand-rolled registration was wrong: register()
  does resolve a relative URL against `<base href>`. The real reason is
  workbox-window's own urlsMatch(), which resolves against location.href, so
  a relative sw URL misidentifies the worker on a route deeper than one
  segment. Comment now says that.
- BASE_URL allows `.`, which is a metacharacter in the two nginx regexes it
  is spliced into: `/it.tools/` also matched `/itXtools/`. The entrypoint now
  exports regex-escaped forms for those, keeping the literal value for the
  sub_filter replacement and the redirect target.
- Dropped `$uri/` from try_files. Nothing in the build is a directory with an
  index, so the only thing it ever produced was nginx's trailing-slash
  redirect -- computed after the prefix rewrite, so `/it-tools/figlet-fonts`
  answered `301 /figlet-fonts/` and bounced the browser out of the app.
- The sub_filter comment claimed index.html was the only response losing
  ETag/Last-Modified; public/visualsubnetcalc/calc.html is HTML too and is
  equally affected. Comment corrected.
- README: in the prefix-stripping proxy setup, `/it-tools` without the
  trailing slash never reaches the container, so the proxy has to redirect it
  (as the sample does). Said so.
- The new e2e test reloaded a page that had just started pulling in a tool's
  chunks; WebKit cancelled the load ~1 run in 3 (the app reloads itself on an
  aborted chunk fetch). It opens the URL in a second tab instead: 8/8 on
  WebKit, 3/3 browsers green.

* fix(build): validate BASE_URL before it reaches the <base href>

From Copilot's review of #10.

The container validates its runtime BASE_URL, but the build-time one went
straight into an HTML attribute unchecked: a value carrying a quote rewrote
the tag around it, and one carrying a space or `..` quietly produced a page
that loads from the wrong place. Apply the same rule the entrypoint does --
a plain path of unreserved characters -- and fail the build otherwise.

Also: "can not" -> "cannot" in the read-only filesystem warning.

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-08-19 22:16:54 +02:00
Sebastian 8b7bc0a650 fix(docker): run on read-only filesystems, IPv6-less hosts and cpu-limited containers (#556)
Five fixes to the Docker image, found while running it-tools on
OpenShift, where containers run as an arbitrary UID. No application code
is changed.

Start on a read-only filesystem. `docker run --read-only` and Kubernetes
readOnlyRootFilesystem crash-loop the container, because
20-envsubst-on-templates.sh checks its output directory with
`[ ! -w $dir ]`. That only reads permission bits, so a read-only mount
passes the check, the write fails with EROFS and `set -e` stops the
entrypoint. 19-skip-envsubst-if-readonly.envsh now tests the directory
with a real write and, on failure, points NGINX_ENVSUBST_TEMPLATE_DIR at
a missing path so the envsubst script exits early. That is only safe if
the config in the image is already correct, and today it is nginx's
stock welcome config, so the Dockerfile renders the template at build
time as well. Writable setups are unchanged: the write test passes,
nothing is exported and the config is rendered at startup as before, so
a custom $PORT still works.

Skip IPv6 when the host has none. nginx.conf always listens on IPv6, so
where IPv6 is off nginx fails with `socket() [::]:8080 failed (97:
Address family not supported by protocol)`.
25-remove-ipv6-listen-if-unavailable.sh comments those lines out, using
the same /proc/net/if_inet6 check as nginx's own
10-listen-on-ipv6-by-default.sh, and exits at once when IPv6 works. It
probes the directory before editing, because `sed -i` rewrites through a
temporary file there, so a writable file in a read-only directory is not
enough, and it tolerates a failed edit so it can never stop the
entrypoint.

Match workers to the cpu limit. `worker_processes auto` counts the
host's cores, not the container's cpu limit, so the image starts 256
workers on a 256-core host in any container size. `docker run -m 192m`
is enough to be OOM-killed at startup. Setting
NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE enables the script nginx
already ships. Containers without a cpu limit keep one worker per core.
This is the only change that affects a deployment that works today.

Return 404 for missing assets. All paths fall back to index.html, so a
missing build file returns 200 and text/html, and the browser reports a
confusing MIME error instead of a 404. /assets/ now skips the SPA
fallback. Sub-folder requests such as /it-tools/assets/... still match
`location /`, so those deployments do not change.

Stop remapping js. nginx.conf includes mime.types, which already maps
js, then maps it again, so every startup logs a duplicate extension
warning. mime.types has no entry for mjs, so mjs stays and js goes.

Signed-off-by: Sebastian Danielsson <sebastian.danielsson@proton.me>
2026-08-14 19:22:10 +02:00
ShareVB c4f7ded565 feat: add Cross Origin Isolation (HTTP Headers) 2026-07-14 18:44:09 +02:00
ShareVB 905de13a84 fix: remove HTTP Headers security as this broke many tools 2026-05-10 23:38:06 +02:00
dragonishandsharevb fe5a33f484 fix(nginx): add comprehensive MIME type mappings (#348)
Include default /etc/nginx/mime.types

---------

Co-authored-by: sharevb <sharevb@gmail.com>
2026-04-19 11:34:03 +02:00
Anastas Mironov 93bed09c78 fix: add JavaScript mjs MIME type (#347)
Add JavaScript MIME types.
2026-04-19 11:34:03 +02:00
ShareVB 0201a9b5c0 feat(new tool): GIF to MP4
Fix #336
2026-04-19 11:34:02 +02:00
ShareVB be14d3a62b fix(Docker): allow PORT environment variable
Taken from #1670
Fix #1450 and #224
2026-01-02 23:54:17 +01:00
ShareVB 608ee95753 fix(Docker): remove CSP header
Break too much tools for now. Fix #184 and #175
2025-09-07 21:02:48 +02:00
ShareVB 6a8d1d30f3 feat(new tool): Font Comparer
Fix #1244
2025-08-22 22:46:43 +02:00
ShareVB 87c7609bc8 fix(Docker/Pomodoro Timer): allow Google Fonts for CSP + fix translation call
Fix #174
2025-08-18 16:27:08 +02:00
ShareVB 438bb09dda fix(Docker): allow image upload (connect-src CSP) in nginx config
Fix #173
2025-08-18 13:46:50 +02:00
ShareVB eafc6f87fc fix(nginx.conf): allow image-src to blob and http(s)
Fix #136
2025-07-20 21:01:17 +02:00
ShareVB 79e0db7ef6 fix: allow connect-src any https: and http:
Fix #135
2025-07-20 21:01:17 +02:00
Reto Kupferschmid 0048f48b47 feat(NGINX): Add some commonly used security headers (#94) 2025-06-15 12:52:47 +02:00
ShareVB 0e9c33ddd3 fix(Docker): baseurl-it-tools, fix rewrite for Traefik
Fix https://github.com/sharevb/it-tools/issues/55#issuecomment-2830765799
2025-05-01 20:43:53 +02:00
Ashutosh Verma a040ac6909 fix(Dockerfile): Docker image listen on both IPv4 and IPv6 (#34) 2025-03-02 20:47:24 +01:00
ShareVB a30b74780d Merge branch 'nginx-unpriviledged' into chore/all-my-stuffs 2025-02-23 13:16:21 +01:00
Lukas Grimm f02a02878d use nginx-unpriviledged 2025-02-14 16:59:23 +01:00
ShareVB 81258f603e fix: serve it-tools in docker for any incoming name
Fix #4
2025-02-02 14:06:10 +01:00
Corentin Thomasset 972ffe6f69 fix(docker): nginx config to redirect to index.html 2023-03-29 00:15:56 +02:00