Commit Graph

55 Commits

Author SHA1 Message Date
Georges-Antoine Assi
025febc17f fix(nginx): keep cross-origin isolation when a player URL carries a query
$request_uri includes the query string, so the end-anchored player pattern
missed /rom/<id>/jsdos?x=1 and nginx dropped COOP and COEP, leaving the
threaded runtime without SharedArrayBuffer. Accept an optional query instead
of anchoring at the path end.

Matching stays on $request_uri: try_files rewrites $uri to /index.html before
add_header runs, so a $uri map would match no player URL at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 11:56:40 -04:00
Georges-Antoine Assi
4142fbc018 refactor: dedupe js-dos emulation checks and player plumbing
usePlatformPlayable is the platform-level twin of useCanPlay, but only the
latter learned about js-dos, so win3x/win9x games offered Play while their
platform tile showed no playable badge and sorted into the unplayable bucket.
Teach resolveEmulator about js-dos and derive `playable`/`isPlayable` from it
instead of hand-maintained OR chains.

Collapse the duplication the new backend introduced: a shared
resolvePlatformSlug in utils, a supportedBy factory for useCanPlay's three
identical computeds, one COOP/COEP nginx pattern per map, and a single
hard-navigation branch in useGameActions that reuses the canPlay useCanPlay
already returns.

In JsDos.vue, share the teardown tail between leavePlayer and onBeforeUnmount,
collapse four derivations of the route rom id into one, start the js-dos
runtime alongside the rom request rather than behind it, and hold the rom in a
shallowRef since the view only reads scalars off it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 10:20:47 -04:00
Bruno Henriques
154340d332 feat: playable Win3.x and Win9.x using js-dos 2026-08-16 18:49:49 +01:00
Georges-Antoine Assi
c70f7d1df3 cleanup 2026-07-23 08:06:42 -04:00
Spinnich
61c3dd1e4c fix(nginx): cache only fingerprinted assets, revalidate the rest
RomM's nginx served everything under /assets, plus the root favicons and
manifest, with no Cache-Control, so browsers re-fetched or revalidated the
frontend bundle and every cover image on repeat visits.

Only some of these assets are safe to cache long-term, so a blanket immutable
rule is unsafe. Cache by fingerprint instead:

- Content-hashed bundles (index-<hash>.js) and library resources that carry a
  cache-busting query (covers ?ts=, manuals ?v=) -> public, max-age=31536000,
  immutable.
- Query-less library resources (screenshots and RA badges, which reuse stable
  filenames and are overwritten on re-scrape), the bundled EmulatorJS/Ruffle
  runtimes, and other static files under /assets -> public, max-age=3600,
  must-revalidate.
- index.html and the root favicons/manifest/service worker -> no-cache, so a
  new deploy's bundles and any updated runtime are picked up at once.

The resources split is driven by an $is_args map, so a resource is frozen only
while its URL carries a busting query.

Fixes #3890

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 22:23:21 +00:00
Georges-Antoine Assi
9488ceba0e Merge pull request #3167 from tmgast/fix/mod-zip-range-requests
feat: Support Range requests for multi-file ROM downloads
2026-07-19 18:32:12 -04:00
Georges-Antoine Assi
168fb2f009 fix(docker): sync nginx upstream port with DEV_PORT
The nginx upstream was hardcoded to 127.0.0.1:5000, while gunicorn and the
readiness check bind/probe ${DEV_PORT}. With a non-default DEV_PORT the
readiness check passes but every proxied request returns 502.

nginx.conf is not run through envsubst, so move the wsgi_server upstream into
the templated default.conf.template and export DEV_PORT in the entrypoint so
the upstream port tracks the gunicorn bind.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 19:05:40 -04:00
Georges-Antoine Assi
cf1420bd5d Merge branch 'master' into fix/mod-zip-range-requests 2026-07-18 18:15:39 -04:00
Georges-Antoine Assi
0ca1eb5529 fix(docker): proxy nginx to gunicorn over TCP instead of unix socket
nginx workers are dropped to the `romm` user while gunicorn creates
/tmp/gunicorn.sock as root. This only worked because gunicorn's default
umask leaves the socket world-writable; on some hosts (e.g. OMV) the
worker cannot connect() and every /api request 502s with
"connect() to unix:/tmp/gunicorn.sock failed (13: Permission denied)".

Proxy over loopback TCP (127.0.0.1:5000), which gunicorn already binds,
so there is no socket file owner/mode to mismatch. Readiness now polls
the TCP port instead of waiting for the socket file.

Fixes #3809

Generated-By: PostHog Code
Task-Id: 3cb72cda-eb77-4bc0-97ab-cde365a031c9
2026-07-18 14:44:08 -04:00
Spinnich
e943cc7e2d fix(nginx): use Buffer for binary-safe base64 decode in m3u endpoint
atob() decodes base64 to a JS string, which r.return() then re-encodes
as UTF-8. For filenames with non-ASCII characters (e.g. Pokémon), bytes
above 0x7F get double-encoded — serving different content than what the
backend computed the CRC32 over, causing mod_zip to report CRC failure
on the .m3u file.

Buffer.from(value, 'base64') decodes directly to a byte array and
r.return() sends it verbatim, matching the CRC exactly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 00:16:23 +00:00
copilot-swe-agent[bot]
681efc6a46 fix: enable COEP/COOP headers for console play route to fix MSDOS games
Agent-Logs-Url: https://github.com/rommapp/romm/sessions/487d4506-1203-499e-afc4-a45ee1f2438b

Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
2026-04-20 18:08:38 +00:00
copilot-swe-agent[bot]
d6036cb5ef fix: respect LOGLEVEL env var for all log output sources
Agent-Logs-Url: https://github.com/rommapp/romm/sessions/0b5ef21c-89e1-4f08-b402-03f3276aab08

Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
2026-04-11 02:13:20 +00:00
nendo
0273d5832c Support Range requests for multi-file ROM downloads
Cache ZIPs to disk on Range requests so nginx can serve 206 natively.
Non-Range requests still stream via mod_zip as before.

Refs: rommapp/romm#3160
2026-03-24 05:56:15 +09:00
zurdi
d6fae786b0 Increase proxy read timeout to 300 seconds for backend API calls 2026-03-03 23:23:25 +00:00
Georges-Antoine Assi
09dbb2e244 use redis to store netplay data 2025-12-07 12:02:35 -05:00
Georges-Antoine Assi
8c769a5fe8 hacks with working netplayu 2025-11-21 19:15:20 -05:00
Georges-Antoine Assi
0d357d59e5 [ROMM-2470] Skip bind IPV6 if IPV4_ONLY is true 2025-10-07 09:07:30 -04:00
Michael Manganiello
0f0d1a1903 fix: Remove mod_zip workaround for upstream subrequests to internal locations
Related `mod_zip` issue https://github.com/evanmiller/mod_zip/issues/90
has been fixed in commit
288d66541c

By upgrading `mod_zip` to include this fix, we can remove the workaround
that involved using a separate internal location and server to serve
files for zipping.
2025-09-11 18:24:12 -03:00
Michael Manganiello
8c52b7828b feat: Add COEP and COOP headers for EmulatorJS within Nginx config
The COEP (Cross-Origin Embedder Policy) and COOP (Cross-Origin Opener
Policy) headers are needed by EmulatorJS to use the `SharedArrayBuffer`
feature, and enable multi-threaded cores.

These headers are only being set by Nginx for responses to requests
made to the EmulatorJS player path. This is because cross-origin
isolation breaks other features in the application (such as YouTube
embeds), so we only want to enable it for the EmulatorJS player.

It's important to mention that this change does not work when `DEV_MODE`
is set, as we would need Vite server to also set these headers in that
case. This could be implemented separately, if needed.

These changes are not enough to enable multi-threaded cores in the
frontend. Because our application is a SPA, we also need to ensure
that navigation to the EmulatorJS player path results in a full page
reload, so that the cross-origin isolation can be applied. This will be
handled in a separate PR.
2025-08-31 21:43:32 -03:00
Daniel Koster
2aa0c204b1 Update default.conf.template
Add IPv6 support
2025-08-04 20:16:59 +02:00
Mark Stapper
365c0efece Fix typo 2025-07-02 08:11:35 +02:00
Mark Stapper
fa3a5c534f Fix Set correct forward proto even when behind reverse proxy 2025-07-01 10:34:19 +02:00
zurdi
53f9386208 refactor: enhance logging messages and formatting for improved clarity and consistency 2025-05-08 23:35:33 +00:00
zurdi
49ad99d5e7 refactor: improve logging setup and format across multiple modules for consistency 2025-05-08 22:17:53 +00:00
zurdi
5bc820d3ee refactor: enhance logging and user agent mapping in nginx configuration for improved monitoring 2025-05-08 17:22:30 +00:00
Michael Manganiello
8487d39326 fix: nginx configuration for library access when ROMM_BASE_PATH is set
The nginx configuration was not updated to use the `ROMM_BASE_PATH`
environment variable when serving the library files.

We no longer hardcode the base path to `/romm`, but instead use the
provided path.
2025-02-21 11:44:48 -03:00
Michael Manganiello
3c4046e2c3 fix: Nginx alias_traversal warning
Warning triggered by [gixy](https://github.com/yandex/gixy).

Related documentation:
https://github.com/yandex/gixy/blob/master/docs/en/plugins/aliastraversal.md
2025-02-19 09:43:26 -03:00
Michael Manganiello
fbff92403f feat: Allow configuring app port using ROMM_PORT environment variable
By using the `ROMM_PORT` environment variable, users can now configure
the port on which the application listens, which defaults to `8080`.
2025-02-19 01:02:25 -03:00
Michael Manganiello
98254d50b8 misc: Use nginx templates to allow for environment variable usage
Using the `envsubst` command, we can replace environment variables in
the nginx template files. This allows for more flexibility when
configuring the nginx server.

The Docker image we use as base for Nginx does provide the
`20-envsubst-on-templates.sh` script that will replace environment
variables in the template files.

This change does not include any behavior change, but unblocks future
changes that require environment variables in the nginx configuration.
2025-02-18 22:36:51 -03:00
Georges-Antoine Assi
d2ab0f4b16 Try to fix nginx proxy buffering on upload 2024-09-21 10:47:24 -04:00
Michael Manganiello
0fad8ac282 feat: Use nginx mod_zip to generate multi-file zip downloads
This change installs and configures the `mod_zip` nginx module [1],
which allows nginx to stream ZIP files directly.

It includes a workaround needed to correctly calculate CRC-32 values for
included files, by including a new `server` section listening at port
8081, only used for the file requests to be upstream subrequests that
correctly trigger the CRC-32 calculation logic.

Also, to be able to provide a `m3u` file generated on the fly, we add a
`/decode` endpoint fully implemented in nginx using NJS, which receives
a `value` URL param, and decodes it using base64. The decoded value is
returned as the response.

That way, the contents of the `m3u` file is base64-encoded, and set as
part of the response, for `mod_zip` to include it in the ZIP file.

[1] https://github.com/evanmiller/mod_zip
2024-08-20 22:39:33 -03:00
Georges-Antoine Assi
9281760975 merge gzip changes into branch 2024-08-13 00:31:48 -04:00
Michael Manganiello
d20f4ad935 feat: Use X-Accel-Redirect to improve file download speed
Instead of making FastAPI handle file download, which has serious
performance issues on big files [1], this change uses nginx's `X-Accel`
feature to delegate single-file downloads to nginx.

Partial fix for #1079, as it solves the CPU usage issue for single-file
downloads.

[1] https://github.com/fastapi/fastapi/discussions/6050
2024-08-12 20:01:00 -03:00
Michael Manganiello
45aeaf3265 fix: Backend URL redirection logic
Fix FastAPI and nginx configuration, to make the application correctly
redirect URLs. This is specially useful when URLs ended with forward
slash are redirected to their stripped version.

Included changes:
* Stop removing the `/api` prefix in nginx rewrite rules, so FastAPI
  knows what's the original URL path being requested.
* Use `$http_host` in nginx, so FastAPI receives both the original host
  and port, to build the redirect URL (as `$host` does not include the
  port, if present).
* Make all FastAPI included routers know their prefix, to correctly
  route incoming requests.

This fix was found based on a report that redirects from URLs ended with
forward slash were not working [1].

[1] https://github.com/rommapp/romm/issues/1051#issuecomment-2269049762
2024-08-05 11:15:52 -03:00
Georges-Antoine Assi
880345f20c ruff-only pre-commit 2024-05-18 12:05:57 -04:00
Psych0D0g
8f5536c69b switch to gunicorn for handling backend app 2024-03-25 21:56:19 +01:00
Georges-Antoine Assi
8a7193d0e4 Add route in nginx for assets that 404s 2024-03-12 15:47:59 +00:00
Georges-Antoine Assi
4b97e21f46 Merge branch 'master' into webrcade-feed 2023-12-27 19:34:58 -05:00
Lukas Wingerberg
74e8875f64 Update nginx default.conf 2023-11-14 09:24:57 +01:00
Lukas Wingerberg
adf8127295 refactor init script and add error handling via watchdog loop 2023-10-31 22:39:08 +01:00
zurdi
174a43888b unlimited client_max_body_size in nginx 2023-10-31 10:01:43 +01:00
zurdi
7001511e26 fix - romm user added to nginx config and dockerfile 2023-10-25 01:33:45 +02:00
Lukas Wingerberg
db282479b0 switch uvicorn and nginx to communicate via unix socket instead of tcp 2023-10-22 13:05:03 +02:00
Lukas Wingerberg
8015558398 refactor to alpine base and fix some more paths to work on readonly rootfs 2023-10-22 12:45:34 +02:00
Lukas Wingerberg
71874810e1 make nginx run successfully on readonly rootfs 2023-10-22 10:55:31 +02:00
Georges-Antoine Assi
c92d8b620b Add access control headers to reponse 2023-09-17 12:13:20 -04:00
Georges-Antoine Assi
7b67495c23 Fix nginx config 2023-08-19 22:00:20 -04:00
Georges-Antoine Assi
c1d1291b48 Expose swaggerui and redoc endpoints 2023-08-18 23:40:18 -04:00
Georges-Antoine Assi
a8a402d250 Add scopes and roles 2023-08-10 23:37:05 -04:00
zurdi zurdo
302b8cf073 scan websocket migrated to socket.io 2023-05-11 14:17:30 +02:00