Skip to content

Commit 23daf95

Browse files
lwshangraymondk
andauthored
infra: switch frontend to certified-assets snapshot wasm + sync plugin (#280)
## Summary - Pulls `canister.wasm` and `plugin.wasm` from the [dfinity/certified-assets `snapshot-pr69-7571cba` release](https://github.com/dfinity/certified-assets/releases/tag/snapshot-pr69-7571cba) via `url:` + `sha256:` so `icp` verifies integrity before use. - Adds `public/_headers` and `public/_redirects` to exercise the new asset-canister tooling's headers and redirects support. - Drops `assets.toml` and the `files:` entry in `icp.yaml`. With [certified-assets PR #66](dfinity/certified-assets#66), `Content-Type` is read directly from `_headers`, so the separate TOML file is no longer needed. The single non-default override (`.did` → `text/plain; charset=utf-8`) now lives in `public/_headers`. - Drops `public/.ic-assets.json5` — the legacy `headers.Content-Type` workaround (which produced duplicate `Content-Type` headers in the certified response) is fully superseded. - Bumps `icp-cli` to v0.2.7. ## Notes - To demo cross-domain redirects: add a line like `/xxx https://google.com 301` in `public/_redirects` and deploy — visiting `/xxx` should bounce to `https://google.com`. ## Test plan - [x] `icp deploy` downloads both wasms, verifies SHA256, and deploys - [x] Headers in `public/_headers` are served on matching paths (CSP, cache rules) - [x] Same-origin redirects in `public/_redirects` resolve (e.g. `/* /404.html 404`) - [x] Cross-domain redirect works after adding `/xxx https://google.com 301` - [x] `curl -I` on `*.md` returns `Content-Type: text/markdown; charset=utf-8` (exactly one header) - [x] `curl -I` on `*.did`, `*.sh`, and `llms.txt` returns `Content-Type: text/plain; charset=utf-8` (exactly one header) --------- Co-authored-by: Raymond Khalife <raymond.khalife@dfinity.org>
1 parent 4d1be64 commit 23daf95

6 files changed

Lines changed: 674 additions & 75 deletions

File tree

.github/workflows/deploy-ic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- run: npm run build
3838

3939
- name: Install icp-cli
40-
run: npm i -g @icp-sdk/icp-cli@0.2.6 @icp-sdk/ic-wasm
40+
run: npm i -g @icp-sdk/icp-cli@0.2.7 @icp-sdk/ic-wasm
4141

4242
- name: Import deploy identity
4343
run: |

.github/workflows/preview-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
python-version: "3.10"
4242

4343
- name: Install icp-cli
44-
run: npm i -g @icp-sdk/icp-cli@0.2.6 @icp-sdk/ic-wasm
44+
run: npm i -g @icp-sdk/icp-cli@0.2.7 @icp-sdk/ic-wasm
4545

4646
- run: npm ci
4747

icp.yaml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
networks:
2+
- name: local
3+
mode: managed
4+
gateway:
5+
port: 0
6+
17
canisters:
28
- name: frontend
3-
recipe:
4-
type: "@dfinity/asset-canister@v2.1.0"
5-
configuration:
6-
dir: dist
7-
version: asset-canister-404-support
8-
build:
9-
- npm install
10-
- npm run build
9+
build:
10+
steps:
11+
- type: pre-built
12+
url: https://github.com/dfinity/certified-assets/releases/download/snapshot-pr69-7571cba/canister.wasm
13+
sha256: aaacb5c927deb57ebd1ec1108b22693b7622b2317ebf6f859f07b7b689aecf5b
14+
15+
sync:
16+
steps:
17+
- type: script
18+
commands:
19+
- npm install
20+
- npm run build
21+
- type: plugin
22+
url: https://github.com/dfinity/certified-assets/releases/download/snapshot-pr69-7571cba/plugin.wasm
23+
sha256: ee9a000ea6f3023f2996b4e9f7d2514298fe2c8fbd9e52e1c6fdf29536fa3628
24+
dirs:
25+
- dist

public/.ic-assets.json5

Lines changed: 0 additions & 65 deletions
This file was deleted.

public/_headers

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Cache-Control is intentionally NOT set on `/*` — `_headers` semantics
2+
# concatenate same-name headers across matching rules with `, `, so a global
3+
# default would corrupt the more-specific overrides below (e.g.
4+
# `public, max-age=0, must-revalidate, public, max-age=31536000, immutable`).
5+
# Pages not covered by a specific rule fall back to browser heuristic caching.
6+
#
7+
# Starlight uses inline <script> tags for theme toggle, mobile menu,
8+
# sidebar state, and search. 'unsafe-inline' is required for these.
9+
# Pagefind search uses WebAssembly, which requires 'wasm-unsafe-eval'.
10+
# 'unsafe-eval' is required by the Matomo Cloud tracker (matomo.js bundles
11+
# plugins such as Form Analytics or Heatmaps that call eval() internally).
12+
# Better long-term fix: disable those plugins in the Matomo Cloud dashboard
13+
# so the bundled matomo.js no longer needs eval(), then remove 'unsafe-eval'.
14+
/*
15+
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' https://cdn.matomo.cloud https://widget.kapa.ai https://metrics.kapa.ai https://hcaptcha.com https://*.hcaptcha.com; style-src 'self' 'unsafe-inline' https://hcaptcha.com https://*.hcaptcha.com; img-src 'self' data: https://www.plantuml.com https://widget.kapa.ai https://www.google.com https://*.gstatic.com; font-src 'self' data:; connect-src 'self' https://icp0.io https://*.icp0.io https://internetcomputer.matomo.cloud https://proxy.kapa.ai https://metrics.kapa.ai https://kapa-widget-proxy-la7dkmplpq-uc.a.run.app https://hcaptcha.com https://*.hcaptcha.com; frame-src https://hcaptcha.com https://*.hcaptcha.com; frame-ancestors 'none'; form-action 'self'; base-uri 'self'; upgrade-insecure-requests
16+
X-Content-Type-Options: nosniff
17+
Referrer-Policy: strict-origin-when-cross-origin
18+
Permissions-Policy: accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()
19+
20+
# Astro hashed bundles — fingerprinted, safe to cache forever.
21+
/_astro/*
22+
Cache-Control: public, max-age=31536000, immutable
23+
24+
# Agent-friendly markdown endpoints — short cache so updates propagate quickly.
25+
/*.md
26+
Cache-Control: public, max-age=300
27+
28+
# llms.txt and other plain-text endpoints — short cache.
29+
/*.txt
30+
Cache-Control: public, max-age=300
31+
32+
# Install scripts — fetched fresh on every `curl | sh`, so no long-lived cache.
33+
/*.sh
34+
Cache-Control: public, max-age=0, must-revalidate
35+
36+
# Candid interface files (e.g., ic.did) — plain text
37+
/*.did
38+
Content-Type: text/plain; charset=utf-8

0 commit comments

Comments
 (0)