Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6b21531
replace virtual modules with generated files, formalize public helper…
BoDonkey Jun 3, 2026
9048c2e
Add changeset
BoDonkey Jun 3, 2026
f1333cf
Helpers cleanup
BoDonkey Jun 4, 2026
a33b84a
Path correction
BoDonkey Jun 4, 2026
a70b170
Add .d.ts and tsconfig files
BoDonkey Jun 4, 2026
83272f4
Remove first design doc
BoDonkey Jun 4, 2026
e9d94cd
Remove final design doc
BoDonkey Jun 4, 2026
99644c0
Better static cache root dir behavior and docs fix
BoDonkey Jun 4, 2026
ffaecff
Bump dependancy
BoDonkey Jun 5, 2026
ea8f042
Refactor for non-bc
BoDonkey Jun 5, 2026
df33277
Migration and version number
BoDonkey Jun 5, 2026
2ab77f9
Response to comments.
BoDonkey Jun 6, 2026
93157d9
Deprecate old files
BoDonkey Jun 6, 2026
564aabb
Fixes upgrade header handling
BoDonkey Jun 17, 2026
32f7a9a
Add tests
BoDonkey Jun 18, 2026
ffdffdc
Fix raw-text sanitization bypass vulnerability and add regression tes…
Dipanshusinghh Jun 4, 2026
c21d5fb
changeset for singh contribution (#5442)
boutell Jun 4, 2026
62d710d
Fix relationship select scrolling issue (#5445)
myovchev Jun 5, 2026
f1dd138
jsx changeset (#5446)
boutell Jun 5, 2026
3bc03d8
Ensure install of the project root for astro projects (#5449)
myovchev Jun 8, 2026
8899103
test node 26 (#5450)
boutell Jun 8, 2026
4e1be7a
Add link for telemetry policy (#5455)
BoDonkey Jun 9, 2026
ff6cbb6
remove absent options (#5456)
boutell Jun 9, 2026
043c215
Remove consumed 4.30.0 changesets from main (#5454)
BoDonkey Jun 10, 2026
6fba442
cli links that are correct, or will be post publish (#5458)
boutell Jun 10, 2026
a6daca5
release db connect to solve chicken and egg problem in cypress-tools …
boutell Jun 10, 2026
227b638
Corrects documentation links (#5457)
BoDonkey Jun 10, 2026
6e6b98c
Merge commit from fork
boutell Jun 10, 2026
6d48f1f
Merge commit from fork
boutell Jun 10, 2026
20a29ea
Merge commit from fork
boutell Jun 10, 2026
736d6c4
Merge commit from fork
boutell Jun 10, 2026
5fda79e
Mergeback latest (#5468)
boutell Jun 10, 2026
5094022
Hotfix cli links (#5469)
BoDonkey Jun 10, 2026
7a29be1
Fix asset URLs when a site prefix is configured (#5448)
Manohar2503 Jun 11, 2026
56a844a
Mergeup latest to main (#5473)
boutell Jun 11, 2026
1937537
fix: treat col as a self-closing tag (#5447)
vansh1011 Jun 16, 2026
57a01ab
Add explicit test for inline configuration collapsing (#5475)
myovchev Jun 17, 2026
334dc61
Pro 9442 insensitive redirects (#5479)
BoDonkey Jun 17, 2026
91ecf47
Bump undici, fix a leak (#5480)
myovchev Jun 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/six-socks-design.md
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
62 changes: 62 additions & 0 deletions packages/apostrophe-astro/MIGRATION.md
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.
4 changes: 2 additions & 2 deletions packages/apostrophe-astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Your `[...slug].astro` component should look like this:

```js
---
import aposPageFetch from '@apostrophecms/apostrophe-astro/lib/aposPageFetch.js';
import { aposPageFetch } from '@apostrophecms/apostrophe-astro/helpers/server';
import AposLayout from '@apostrophecms/apostrophe-astro/components/layouts/AposLayout.astro';
import AposTemplate from '@apostrophecms/apostrophe-astro/components/AposTemplate.astro';

Expand Down Expand Up @@ -651,7 +651,7 @@ links to each page of blog posts:

```js
---
import setParameter from '@apostrophecms/apostrophe-astro/lib/aposSetQueryParameter.js';
import { aposSetQueryParameter as setParameter } from '@apostrophecms/apostrophe-astro/helpers/universal';

const {
pieces,
Expand Down
2 changes: 1 addition & 1 deletion packages/apostrophe-astro/components/AposTemplate.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { templates } from 'virtual:apostrophe-doctypes';
import { templates } from 'apostrophe-astro-config/doctypes';

const { aposData } = Astro.props;

Expand Down
2 changes: 1 addition & 1 deletion packages/apostrophe-astro/components/AposWidget.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { widgets } from "virtual:apostrophe-doctypes";
import { widgets } from 'apostrophe-astro-config/doctypes';

const { widget, options, ...props } = Astro.props;
const isEdit = widget._edit && Astro.url.searchParams.get("aposEdit");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import config from "virtual:apostrophe-config";
import config from 'apostrophe-astro-config/config';

const { title, bodyClass, aposData } = Astro.props;
const { viewTransitionWorkaround } = config;
Expand Down
7 changes: 5 additions & 2 deletions packages/apostrophe-astro/components/layouts/AposLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import AposRunLayout from "./AposRunLayout.astro";
import AposEditLayout from "./AposEditLayout.astro";
import AposRefreshLayout from "./AposRefreshLayout.astro";
import config from 'virtual:apostrophe-config';
import config from 'apostrophe-astro-config/config';

const { aposData } = Astro.props;

Expand All @@ -13,7 +13,10 @@ if (!headersToInclude && config.forwardHeaders) {
headersToInclude = config.forwardHeaders;
}

if (headersToInclude && Array.isArray(headersToInclude)) {
// Response headers are only meaningful in SSR — prerendered static pages
// have no per-request HTTP response, and accessing Astro.response.headers
// in that context triggers a warning in Astro v6.
if (!config.staticBuild && headersToInclude && Array.isArray(headersToInclude)) {
const headers = aposData.aposResponseHeaders;
if (headers) {
for (const header of headersToInclude) {
Expand Down
2 changes: 1 addition & 1 deletion packages/apostrophe-astro/endpoints/renderWidget.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import AposWidget from "../components/AposWidget.astro";
import aposRequest from "../lib/aposRequest.js";
import aposResponse from "../lib/aposResponse.js";
import { onBeforeWidgetRenderHook } from "virtual:apostrophe-doctypes";
import { onBeforeWidgetRenderHook } from 'apostrophe-astro-config/doctypes';

const request = aposRequest(Astro.request);
const response = await aposResponse(request);
Expand Down
17 changes: 14 additions & 3 deletions packages/apostrophe-astro/helpers/index.js
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';

Copy link
Copy Markdown
Contributor

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.

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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/helpers/server/static.js re-exports the lib so that the project can import from /helpers/server , however the helpers/server/fetch.js now is reverted (as requested) but doesn't re-export the lib. This sends mixed signals - the project will import static from helpers but the standard page loading from /lib? I think aposPageFetch() should be also re-exported here.


/**
* 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/...`).
*
Expand All @@ -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();
* ---
Expand All @@ -50,3 +50,4 @@ export async function aposFetch(input, init) {
headers
});
}

14 changes: 14 additions & 0 deletions packages/apostrophe-astro/helpers/server/index.js
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';
9 changes: 9 additions & 0 deletions packages/apostrophe-astro/helpers/server/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';
55 changes: 55 additions & 0 deletions packages/apostrophe-astro/helpers/server/url.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);
}
19 changes: 0 additions & 19 deletions packages/apostrophe-astro/helpers/slug.js

This file was deleted.

Loading
Loading