Skip to content

fix(nginx): route /plugin-sdk/ and /index.css to the backend - #155

Merged
Szeraax merged 1 commit into
jherforth:mainfrom
mrramam:task/61-nginx-plugin-sdk
Sep 7, 2026
Merged

fix(nginx): route /plugin-sdk/ and /index.css to the backend#155
Szeraax merged 1 commit into
jherforth:mainfrom
mrramam:task/61-nginx-plugin-sdk

Conversation

@mrramam

@mrramam mrramam commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #154.

nginx has no location for /plugin-sdk/ or /index.css, so both are captured by the static-asset regex and returned as 404. In any deployment where nginx serves the frontend, a plugin iframe cannot load the SDK or the theme variables.

Two location blocks, placed before the static-asset regex:

  • location ^~ /plugin-sdk/ — proxied to the backend, which already serves /plugin-sdk/v1.js.
  • location = /index.css — proxied to the backend, which already serves it.

^~ and = are load-bearing rather than stylistic. nginx matches regex locations before prefix locations, so a plain location /plugin-sdk/ would still lose to the .js|.css static-asset regex and 404 exactly as before. = /index.css wins as an exact match without shadowing the hashed stylesheets under /assets/. Both carry the same proxy headers as the existing /widgets/ block.

No behaviour changes outside those two paths.

Verified

On a container deployment before and after, through nginx:

Path Before After
/plugin-sdk/v1.js 404 200 application/javascript
/index.css 404 200 text/css

The served SDK is byte-identical to server/plugin-sdk/v1.js at this commit (sha256 comparison, not a status code).

Unchanged after the patch: /api/, /uploads/, /Uploads/, /widgets/, = /index.html, the SPA fallback, and hashed assets under /assets/ (still Cache-Control: max-age=31536000, public, immutable).

End to end, a plugin declaring apiVersion: "v1" now reaches window.HomeGlow.pluginId, stores server-side (confirmed across two browsers), and picks up the theme variables from /index.css.

nginx -t passes.

Note for anyone deploying this

Plugins already installed that load the SDK have been silently falling back to browser-local storage, because they guard on window.HomeGlow. Once the SDK loads they read server-side settings, which will be empty where a display currently shows local data — so expect a one-time reset of those plugins' settings rather than a migration of them.

I have not included any migration code or docs for that stranded localStorage data. Happy to follow up with it in a separate PR (or to add it here) if you would like it — it would have to live in each affected plugin, since only code running in that browser can read its localStorage.

The plugin SDK is served by Fastify at /plugin-sdk/v1.js and the theme
stylesheet at /index.css, but nginx had no location for either. Both were
captured by the static-asset regex and returned 404, so in any container
deployment a plugin iframe could not load the SDK or the theme variables.

Plugin iframes are same-origin with the frontend: PluginWidgetWrapper sets
src to `${API_BASE_URL}/widgets/<file>`, and VITE_REACT_APP_API_URL has no
default and is not set by docker-compose.yml, so API_BASE_URL compiles to ''.
Native dev points it at the backend, which is why this only affects
containers.

Plugins that load the SDK guard on `window.HomeGlow` and silently fall back
to browser-local behaviour, so the failure surfaced as features quietly not
working rather than as an error.

`^~` and `=` are required rather than stylistic: nginx matches regex
locations before prefix locations, so a plain prefix location would still
lose to the static-asset regex and 404 as before.

Verified through nginx: /plugin-sdk/v1.js 200 application/javascript,
/index.css 200 text/css, with /api/, /uploads/, /widgets/, hashed assets
and the SPA fallback unchanged.
@Szeraax
Szeraax merged commit becf449 into jherforth:main Sep 7, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in HomeGlow Kanban Sep 7, 2026
@mrramam
mrramam deleted the task/61-nginx-plugin-sdk branch September 12, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

nginx does not route /plugin-sdk/ or /index.css, so the plugin SDK is unreachable in container deployments

2 participants