@easy-web/swa 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,9 +8,14 @@ When you add `easyWebNotFound()` to your Astro config, the integration:
|
|
|
8
8
|
|
|
9
9
|
1. **Reads** the existing `staticwebapp.config.json` at build time (if present)
|
|
10
10
|
2. **Emits** a global 404 response override (`responseOverrides.404`) that rewrites unmatched routes to `/404.html`
|
|
11
|
-
3. **Derives** `trailingSlash` from your Astro config
|
|
11
|
+
3. **Derives** `trailingSlash` from your Astro config, unless user-owned, to align with the canonical URLs `@easy-web/core/seo` emits
|
|
12
12
|
4. **Tracks ownership** via a sidecar file (`staticwebapp.config.json.easy-web-managed.json`) so future builds know which settings the integration manages
|
|
13
|
-
5. **Preserves**
|
|
13
|
+
5. **Preserves values** of unrelated schema-legal settings, including `auth`, `globalHeaders`, `navigationFallback`, custom routes, and other `responseOverrides`, while reserializing the config
|
|
14
|
+
|
|
15
|
+
It does **not** create 404 pages or localized routes. The site supplies the
|
|
16
|
+
`/404.html` artifact and owns its layout and content; the host-independent
|
|
17
|
+
[`NotFound` component and artifact checks](https://achim.ismaili.de/easy-web/docs/packages/core/#not-found-page-ownership)
|
|
18
|
+
live in `@easy-web/core`. SWA is optional, not a requirement for core consumers.
|
|
14
19
|
|
|
15
20
|
## Usage
|
|
16
21
|
|
|
@@ -43,21 +48,38 @@ SWA's `staticwebapp.config.json` schema uses `additionalProperties: false` at th
|
|
|
43
48
|
}
|
|
44
49
|
```
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
At `astro:build:done`, the integration reads the config and sidecar from Astro's
|
|
52
|
+
reported output directory, then writes both there. For a static build, source
|
|
53
|
+
config normally reaches that directory via Astro's `public/` copy. A config left
|
|
54
|
+
only at the repository root is not read by this integration. If ownership metadata
|
|
55
|
+
must survive a clean build, it must also reach the output directory (for example,
|
|
56
|
+
via a reviewed sidecar in `public/`); an old output file is not a durable source of
|
|
57
|
+
ownership.
|
|
58
|
+
|
|
59
|
+
If the sidecar claims `responseOverrides.404`, that slot is refreshed. If the slot
|
|
60
|
+
exists without a sidecar claim, the user's override wins with a warning and remains
|
|
61
|
+
unclaimed. If it is absent, the integration creates and claims it. The same
|
|
62
|
+
ownership rule applies to `trailingSlash`, subject to the derivation below.
|
|
63
|
+
Sidecar `version` is a bookkeeping marker, not the installed package version.
|
|
64
|
+
Do not put the old `$easyWebManaged` metadata key in the SWA config root.
|
|
47
65
|
|
|
48
66
|
### Single global 404 limitation
|
|
49
67
|
|
|
50
68
|
Azure Static Web Apps supports only **one global 404 response override**. This integration emits a single, locale-agnostic 404 handler. If your site uses i18n:
|
|
51
69
|
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
-
|
|
70
|
+
- When the managed override handles a missing route, it serves `/404.html`,
|
|
71
|
+
regardless of locale prefix. Make that artifact the site's default-locale body.
|
|
72
|
+
- Explicitly authored localized 404 pages can still render localized content, but
|
|
73
|
+
the global fallback does not select them by the missing URL's locale.
|
|
74
|
+
- Adding locales does not generate routes, pages or additional overrides.
|
|
55
75
|
|
|
56
|
-
|
|
76
|
+
Do not add greedy `/<locale>/*` rewrites to imitate localized fallbacks: they can
|
|
77
|
+
shadow valid pages. Existing routes and `navigationFallback` are preserved, not
|
|
78
|
+
repaired; they may intercept requests before this 404 override is used.
|
|
57
79
|
|
|
58
80
|
### Trailing slash
|
|
59
81
|
|
|
60
|
-
|
|
82
|
+
The integration derives an explicit `trailingSlash` from your Astro config - the same config that drives canonical, hreflang and sitemap URLs emitted by `@easy-web/core/seo`. A user-owned SWA value still wins and must be reviewed for consistency.
|
|
61
83
|
|
|
62
84
|
| Astro config | Emitted `trailingSlash` | SWA behaviour |
|
|
63
85
|
| :--- | :--- | :--- |
|
|
@@ -80,16 +102,49 @@ Setting `trailingSlash` yourself in `staticwebapp.config.json` still wins, with
|
|
|
80
102
|
|
|
81
103
|
## Preservation guarantees
|
|
82
104
|
|
|
83
|
-
The
|
|
105
|
+
The not-found managed surface is **only `responseOverrides.404`**:
|
|
84
106
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"responseOverrides": {
|
|
110
|
+
"404": { "rewrite": "/404.html", "statusCode": 404 }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
91
114
|
|
|
92
|
-
|
|
115
|
+
The integration also manages `trailingSlash` as described above; it emits no
|
|
116
|
+
locale-wide rewrite routes. Unrelated schema-legal root values and other response
|
|
117
|
+
overrides survive the merge, but preservation is **value-based, not byte-for-byte**:
|
|
118
|
+
the whole JSON file is rewritten with two-space indentation and a trailing newline.
|
|
119
|
+
Unknown root keys, including the legacy `$easyWebManaged` key, are omitted with a
|
|
120
|
+
warning. This filtering is not full SWA schema validation.
|
|
121
|
+
|
|
122
|
+
Malformed JSON, non-object documents, malformed sidecar metadata and a non-object
|
|
123
|
+
`responseOverrides` fail the build. Review source configuration and ownership
|
|
124
|
+
together; changing a managed output slot alone will be undone when its sidecar
|
|
125
|
+
claim is present. See the [adoption checklist](./MIGRATION.md) for ownership changes.
|
|
126
|
+
|
|
127
|
+
## Validation boundaries
|
|
128
|
+
|
|
129
|
+
Package merge tests exercise config/sidecar ownership and serialization; they do
|
|
130
|
+
not prove a consuming site's 404 page exists or that a deployed host uses it.
|
|
131
|
+
Alongside the [core artifact checks](https://achim.ismaili.de/easy-web/docs/packages/core/#validate-artifacts-separately-from-hosting),
|
|
132
|
+
inspect the site's emitted `staticwebapp.config.json` and sibling sidecar:
|
|
133
|
+
|
|
134
|
+
- If integration-owned, verify `responseOverrides.404` is exactly the managed
|
|
135
|
+
rewrite/status above and `/404.html` exists in the deployable artifact.
|
|
136
|
+
- Verify sidecar claims match the intended ownership, no metadata root key or
|
|
137
|
+
unintended locale-wide rewrite was introduced, and unrelated values remain.
|
|
138
|
+
- Review retained routes, `navigationFallback`, and trailing-slash behavior for
|
|
139
|
+
conflicts. Preserving their values does not certify their routing or auth behavior.
|
|
140
|
+
|
|
141
|
+
After deployment, the site operator should request a unique nonexistent URL on
|
|
142
|
+
the actual target, including locale-prefixed paths, and check HTTP 404 plus the
|
|
143
|
+
expected global fallback body and home link. Request valid pages too, to catch
|
|
144
|
+
overbroad rewrites. This is a separate operator-owned check, not something the
|
|
145
|
+
integration, `astro preview`, or this guide runs automatically. No SWA CLI or
|
|
146
|
+
browser harness is required for filesystem/HTML artifact checks; local simulation
|
|
147
|
+
alone cannot establish deployed-platform behavior.
|
|
93
148
|
|
|
94
149
|
## Compatibility
|
|
95
150
|
|
package/package.json
CHANGED