-
Notifications
You must be signed in to change notification settings - Fork 642
Pro 9551 apos astro v2 #5441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Pro 9551 apos astro v2 #5441
Changes from 13 commits
6b21531
9048c2e
f1333cf
a33b84a
a70b170
83272f4
e9d94cd
99644c0
ffaecff
ea8f042
df33277
2ab77f9
93157d9
564aabb
32f7a9a
ffdffdc
c21d5fb
62d710d
f1dd138
3bc03d8
8899103
4e1be7a
ff6cbb6
043c215
6fba442
a6daca5
227b638
6e6b98c
6d48f1f
20a29ea
736d6c4
5fda79e
5094022
7a29be1
56a844a
1937537
57a01ab
334dc61
91ecf47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| "@apostrophecms/apostrophe-astro": minor | ||
| --- | ||
|
|
||
| - Replace vite-plugin-apostrophe-config and vite-plugin-apostrophe-doctype with | ||
| vite/vite-plugin-apostrophe-generated-config.js, which writes real files to | ||
| node_modules/.apostrophe-astro-config/ (config.js, doctypes.js) | ||
| - Register Vite aliases for apostrophe-astro-config/config and /doctypes | ||
| - Update all internal virtual: imports to alias specifiers | ||
| - Rename static build cache dir to node_modules/.apostrophe-astro-static/ | ||
| - Add helpers/server/ (aposFetch, getAposHost, isStaticBuild) | ||
| - Add helpers/universal/ (URL, slug, styles, attachment helpers) | ||
| - Keep lib/aposPageFetch.js as the internal implementation (starter kit entrypoint only) | ||
| - Reduce lib/util.js, lib/aposSetQueryParameter.js, lib/static.js to deprecated shims | ||
| - Add MIGRATION.md | ||
| - Bump undici to ^7.x for Node.js 24+ compatibility |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Migrating to @apostrophecms/apostrophe-astro v1.13 | ||
|
|
||
| ## Astro v6 support | ||
|
|
||
| v1.13 adds support for Astro v6 (Vite 7). Astro v5 continues to work. | ||
|
|
||
| --- | ||
|
|
||
| ## Astro v6: remove `security.allowedDomains` from static builds | ||
|
|
||
| If your project uses `security.allowedDomains` in `astro.config.mjs` **and** runs static builds, guard it to SSR-only. In a static build Astro v6 reads `request.headers` to validate forwarded headers even during prerendering, producing a spurious warning for every page: | ||
|
|
||
| ``` | ||
| [WARN] `Astro.request.headers` was used when rendering the route `src/pages/[...slug].astro` | ||
| ``` | ||
|
|
||
| `allowedDomains` has no effect during prerendering (there are no real HTTP headers at build time), so the fix is straightforward: | ||
|
|
||
| ```js | ||
| // astro.config.mjs | ||
| const isStatic = process.env.APOS_BUILD === 'static'; // or however you detect it | ||
|
|
||
| export default defineConfig({ | ||
| output: isStatic ? 'static' : 'server', | ||
| // Only configure allowedDomains for SSR — it is meaningless during | ||
| // static prerendering and triggers a spurious headers warning in Astro v6. | ||
| ...(!isStatic && { | ||
| security: { allowedDomains } | ||
| }), | ||
| // ... | ||
| }); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Deprecated: direct `lib/` imports for public helpers | ||
|
|
||
| Some `lib/` paths are deprecated in favour of the stable helper entry points. Note that `lib/aposPageFetch.js` is **not** deprecated — it is an internal function used by the starter kit's `[...slug].astro` entrypoint and is not part of the public API. | ||
|
|
||
| | Old import | New import | | ||
| |---|---| | ||
| | `@apostrophecms/apostrophe-astro/lib/static.js` | `@apostrophecms/apostrophe-astro/helpers/server` (`getAllStaticPaths`, `getAllUrlMetadata`, `getLocales`) | | ||
| | `@apostrophecms/apostrophe-astro/lib/aposSetQueryParameter.js` | `@apostrophecms/apostrophe-astro/helpers/universal` (`aposSetQueryParameter`) | | ||
| | `@apostrophecms/apostrophe-astro/lib/util.js` | `@apostrophecms/apostrophe-astro/helpers/universal` (`slugify`, etc.) | | ||
| | `@apostrophecms/apostrophe-astro/lib/aposStyles.js` | `@apostrophecms/apostrophe-astro/helpers/universal` (`stylesAttributes`, `stylesElements`) | | ||
| | `@apostrophecms/apostrophe-astro/lib/attachment.js` | `@apostrophecms/apostrophe-astro/helpers/universal` (`getAttachmentUrl`, `getAttachmentSrcset`, etc.) | | ||
|
|
||
| Example: | ||
|
|
||
| ```js | ||
| // Before | ||
| import { getAllStaticPaths } from '@apostrophecms/apostrophe-astro/lib/static.js'; | ||
|
|
||
| // After | ||
| import { getAllStaticPaths } from '@apostrophecms/apostrophe-astro/helpers/server'; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Removed: Vite virtual modules | ||
|
|
||
| `virtual:apostrophe-config` and `virtual:apostrophe-doctypes` were private implementation details and are no longer available. If you were importing either of these directly, remove those imports — there is no public replacement, as they were never part of the supported API. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,14 @@ | ||
| export { getAposHost, isStaticBuild, buildPageUrl, getFilterBaseUrl, aposSetQueryParameter } from './url.js'; | ||
| export { slugify } from './slug.js'; | ||
| export { aposFetch } from './fetch.js'; | ||
| /** | ||
| * @deprecated Import from the scoped sub-paths instead: | ||
| * | ||
| * ```js | ||
| * // Server-side helpers (Astro frontmatter, endpoints, prerendering) | ||
| * import { aposFetch, getAposHost, isStaticBuild, getAllStaticPaths } from '@apostrophecms/apostrophe-astro/helpers/server'; | ||
| * | ||
| * // Universal helpers (server + client) | ||
| * import { slugify, getAttachmentUrl, aposSetQueryParameter } from '@apostrophecms/apostrophe-astro/helpers/universal'; | ||
| * ``` | ||
| */ | ||
|
|
||
| export { aposFetch, getAposHost, isStaticBuild, getAllStaticPaths, getAllUrlMetadata, getLocales } from './server/index.js'; | ||
| export { buildPageUrl, getFilterBaseUrl, aposSetQueryParameter, slugify, stylesElements, stylesAttributes, getFocalPoint, getAttachmentUrl, getAttachmentSrcset, getWidth, getHeight } from './universal/index.js'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import config from 'virtual:apostrophe-config'; | ||
| import config from 'apostrophe-astro-config/config'; | ||
| import { getAposHost } from './url.js'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| /** | ||
| * A transparent proxy around the native `fetch` API for **server-side | ||
| * Astro code only** (`.astro` frontmatter, server endpoints, etc.). | ||
| * | ||
| * **Do NOT use in client-side code** — it depends on | ||
| * `virtual:apostrophe-config` and exposes the internal backend host. | ||
| * `apostrophe-astro-config/config` and exposes the internal backend host. | ||
| * For browser requests use plain `fetch` with relative URLs | ||
| * (e.g. `/api/v1/...`). | ||
| * | ||
|
|
@@ -28,7 +28,7 @@ import { getAposHost } from './url.js'; | |
| * @example | ||
| * ```astro | ||
| * --- | ||
| * import { aposFetch } from '@apostrophecms/apostrophe-astro/helpers'; | ||
| * import { aposFetch } from '@apostrophecms/apostrophe-astro/helpers/server'; | ||
| * const response = await aposFetch('/api/v1/article?perPage=5'); | ||
| * const data = await response.json(); | ||
| * --- | ||
|
|
@@ -50,3 +50,4 @@ export async function aposFetch(input, init) { | |
| headers | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * Server-only public helpers for @apostrophecms/apostrophe-astro. | ||
| * | ||
| * Use these in Astro frontmatter, server endpoints, prerendering routes, | ||
| * and any other server-side code. Do not import this module from | ||
| * client-side scripts — it depends on generated integration config and | ||
| * Node.js internals unavailable in browsers. | ||
| * | ||
| * @module @apostrophecms/apostrophe-astro/helpers/server | ||
| */ | ||
|
|
||
| export { aposFetch } from './fetch.js'; | ||
| export { getAposHost, isStaticBuild } from './url.js'; | ||
| export { getAllStaticPaths, getAllUrlMetadata, getLocales } from './static.js'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * Static build helpers — server-only. | ||
| * | ||
| * Re-exports the public static-build functions from `lib/static.js`. | ||
| * Use these in `getStaticPaths()` inside your `[...slug].astro` page | ||
| * to fetch all page paths and props from the Apostrophe backend. | ||
| */ | ||
|
|
||
| export { getAllStaticPaths, getAllUrlMetadata, getLocales } from '../../lib/static.js'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import config from 'apostrophe-astro-config/config'; | ||
|
|
||
| /** | ||
| * Get the Apostrophe backend base URL, including the prefix when | ||
| * configured. | ||
| * | ||
| * Returns `config.aposHost + config.aposPrefix` — the full base URL | ||
| * for reaching the Apostrophe backend (e.g. | ||
| * `http://localhost:3000/my-repo`). Environment variable overrides | ||
| * (`APOS_HOST`, `APOS_PREFIX`) are resolved once at config time in | ||
| * the integration's `astro:config:setup` hook and stored in the | ||
| * generated config module — this function does no env lookups. | ||
| * | ||
| * Prefer `aposFetch` for API calls — use `getAposHost()` only when | ||
| * you need the raw URL string (e.g. for building non-fetch URLs). | ||
| * | ||
| * WARNING: not to be confused with "Public Host" — this is meant to | ||
| * be used only in Astro server-side code. Use relative URLs for | ||
| * client-side requests `/api/v1/...`. | ||
| * | ||
| * @returns {string} The backend base URL (e.g. `http://localhost:3000` | ||
| * or `http://localhost:3000/my-repo`). | ||
| * | ||
| * @example | ||
| * ```astro | ||
| * --- | ||
| * import { getAposHost } from '@apostrophecms/apostrophe-astro/helpers/server'; | ||
| * const host = getAposHost(); | ||
| * // e.g. 'http://localhost:3000' or 'http://localhost:3000/my-repo' | ||
| * --- | ||
| * ``` | ||
| */ | ||
| export function getAposHost() { | ||
| return config.aposHost + (config.aposPrefix || ''); | ||
| } | ||
|
|
||
| /** | ||
| * Check whether the current build is a static build. | ||
| * | ||
| * Returns `true` when the Astro integration is configured for | ||
| * static output (e.g. `output: 'static'`). | ||
| * | ||
| * @returns {boolean} | ||
| * | ||
| * @example | ||
| * ```astro | ||
| * --- | ||
| * import { isStaticBuild } from '@apostrophecms/apostrophe-astro/helpers/server'; | ||
| * --- | ||
| * <html data-static={isStaticBuild()}> | ||
| * ``` | ||
| */ | ||
| export function isStaticBuild() { | ||
| return process.env.APOS_ASTRO_STATIC_BUILD === '1' || Boolean(config.staticBuild); | ||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now re-exports everything. I think it should only re-export what was exported previously.