|
| 1 | +# Installing the Star Wars app on a Horizon instance |
| 2 | + |
| 3 | +The bundle is instance-independent — `publicPath: 'auto'`, no hostnames baked |
| 4 | +in — and published once, to GitHub Pages, for every instance. Installing it on |
| 5 | +a portal is two API calls and no files: **register**, then **deploy** (which is |
| 6 | +what verifies it). |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +- Horizon v46+ with SDK support (`NsApi.horizon_extensions` table exists). |
| 11 | +- `*.github.io` in `approved_cdn_origins` (`NsApi.horizon_extension_settings`). |
| 12 | + It is what `horizon-sdk-demo` loads through, so on most instances this is |
| 13 | + already true. Failure here is silent in the UI — look for |
| 14 | + `[HorizonAppsLoader]` in the browser console. |
| 15 | +- Browsers reaching the portal can reach `raw.githubusercontent.com` (the |
| 16 | + character index) and Fandom's image CDN (the portraits). |
| 17 | +- For the **Set as my avatar** button only: the API-write master capability |
| 18 | + enabled for SDK apps, and `avatar` absent from `api_write_deny_resources`. |
| 19 | + Both are platform-global settings; everything else in the app is read-only |
| 20 | + against public data and needs neither. |
| 21 | +- A token with write scope. `reseller: *` (platform-global) requires a super |
| 22 | + user; a reseller-scoped token can only create within its own reseller. |
| 23 | + |
| 24 | +## 1. Publish the bundle |
| 25 | + |
| 26 | +Pushing to `main` does this — see the README. Confirm what the platform will |
| 27 | +fetch: |
| 28 | + |
| 29 | +```bash |
| 30 | +curl -sI https://netsapiens.github.io/horizon-starwars-app/remoteEntry.js \ |
| 31 | + | grep -iE 'http/|content-type|access-control-allow-origin' |
| 32 | +# -> 200, application/javascript, access-control-allow-origin: * |
| 33 | +``` |
| 34 | + |
| 35 | +## 2. Register the app |
| 36 | + |
| 37 | +Portal **Platform -> UI SDK Management -> Registered Apps -> Add App** is the |
| 38 | +short path — it registers and gives you the **Deploy** button step 3 needs. |
| 39 | + |
| 40 | +The API equivalent (note the `/registry` segment — `POST /ui-extensions` is a |
| 41 | +runtime read surface and returns 405): |
| 42 | + |
| 43 | +```bash |
| 44 | +curl -X POST "https://<PORTAL_FQDN>/ns-api/v2/ui-extensions/registry" \ |
| 45 | + -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" \ |
| 46 | + -d '{ |
| 47 | + "name": "Star Wars", |
| 48 | + "description": "Star Wars character browser, with avatar adoption", |
| 49 | + "version": "1.0.0", |
| 50 | + "remote_entry_url": "https://netsapiens.github.io/horizon-starwars-app/remoteEntry.js", |
| 51 | + "webpack_module": "horizonStarwars", |
| 52 | + "enabled": "yes" |
| 53 | + }' |
| 54 | +``` |
| 55 | + |
| 56 | +Required fields are `name`, `remote_entry_url` and `webpack_module`; everything |
| 57 | +else has a default. **Do not send `id`** — the server derives it as the |
| 58 | +kebab-case of `webpack_module` (`horizonStarwars` -> `horizon-starwars`). |
| 59 | +`webpack_module` is unique platform-wide (409 on a duplicate) and immutable |
| 60 | +once registered. |
| 61 | + |
| 62 | +## 3. Deploy the bundle (required — this is what verifies it) |
| 63 | + |
| 64 | +A registered app sits at `verification_status: none`, is filtered out of |
| 65 | +`/ui-extensions?purpose=runtime` before the browser sees it, and renders |
| 66 | +nowhere. One call fetches, verifies, hashes and promotes: |
| 67 | + |
| 68 | +```bash |
| 69 | +curl -X POST "https://<PORTAL_FQDN>/ns-api/v2/ui-extensions/registry/horizon-starwars/deploy?synchronous=yes" \ |
| 70 | + -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" \ |
| 71 | + -d '{ "remote_entry_url": "https://netsapiens.github.io/horizon-starwars-app/remoteEntry.js" }' |
| 72 | +``` |
| 73 | + |
| 74 | +or press **Deploy** on the app's row in Registered Apps, which does the same |
| 75 | +thing and picks the next free version itself. |
| 76 | + |
| 77 | +Reading the response: |
| 78 | + |
| 79 | +- `status` — `approved` and `flagged` both load; only `rejected` blocks. |
| 80 | + A `size-delta` flag on a first submission is expected. |
| 81 | +- `promoted: true` is the bit that matters; `synchronous=yes` adds `landed`, |
| 82 | + and `landed: false` means "not observed within the poll budget", not failed. |
| 83 | +- `unchanged: true` means the fetched bytes hash to the current pin — a success. |
| 84 | +- `429` is the per-extension submission rate limit. Wait a minute. |
| 85 | + |
| 86 | +## 4. Verify in the portal |
| 87 | + |
| 88 | +Hard-refresh: **Star Wars** appears in the **Apps** menu (deep link: |
| 89 | +`https://<PORTAL_FQDN>/apps/starwars`). |
| 90 | + |
| 91 | +Then click a character and press **Set as my avatar**. Success says so in the |
| 92 | +panel; the top bar shows the new picture on the next page load, because the |
| 93 | +host reads the avatar once per load. |
| 94 | + |
| 95 | +## Updating |
| 96 | + |
| 97 | +Bump `version` in `package.json`, push to `main`, wait for the Pages deploy to |
| 98 | +finish, then deploy again (step 3). Between the publish and the deploy the |
| 99 | +platform still pins the previous hash while the CDN serves new bytes, so keep |
| 100 | +the gap short. |
| 101 | + |
| 102 | +## Appendix: if the portrait cannot be read |
| 103 | + |
| 104 | +The avatar button fetches the portrait's bytes so it can crop them to a square. |
| 105 | +That read — unlike simply displaying the image — needs the image host to allow |
| 106 | +it. Two things can block it, and the panel reports both: |
| 107 | + |
| 108 | +- **The image CDN sends no CORS header** for this origin. The fetch fails with |
| 109 | + a bare `TypeError`, with the real reason only in the console. |
| 110 | +- **The portal's Content-Security-Policy** restricts `connect-src` or |
| 111 | + `img-src`. |
| 112 | + |
| 113 | +Either way, putting the images on the portal's own origin removes the question: |
| 114 | + |
| 115 | +```apache |
| 116 | +<Location "/swimages/"> |
| 117 | + ProxyPass "https://static.wikia.nocookie.net/" timeout=30 |
| 118 | + ProxyPassReverse "https://static.wikia.nocookie.net/" |
| 119 | +</Location> |
| 120 | +``` |
| 121 | + |
| 122 | +Then rewrite each record's `image` in `src/api/starwarsApi.ts` to that prefix |
| 123 | +as the index is mapped, and rebuild. Needs `proxy_http` and proxy SSL support. |
| 124 | +Consider caching: these are somebody else's images and somebody else's |
| 125 | +bandwidth. |
| 126 | + |
| 127 | +A portal that cannot allow either is still fine for the rest of the app — the |
| 128 | +grid, the search and the detail panel all work, and only the avatar button |
| 129 | +fails, with an explanation. |
0 commit comments