summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/lemon-flowers-tease.md5
-rw-r--r--packages/astro/src/core/util.ts2
-rw-r--r--packages/astro/src/vite-plugin-scanner/index.ts10
-rw-r--r--packages/astro/test/fixtures/ssr-manifest/astro.config.mjs22
-rw-r--r--packages/astro/test/fixtures/ssr-manifest/entrypoint-test.js9
-rw-r--r--packages/astro/test/fixtures/ssr-manifest/src/pages/index.astro17
-rw-r--r--packages/astro/test/fixtures/ssr-manifest/src/pages/manifest.json.js5
-rw-r--r--packages/astro/test/ssr-manifest.test.js34
8 files changed, 73 insertions, 31 deletions
diff --git a/.changeset/lemon-flowers-tease.md b/.changeset/lemon-flowers-tease.md
new file mode 100644
index 000000000..e4b2b3f5f
--- /dev/null
+++ b/.changeset/lemon-flowers-tease.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes injected endpoint `prerender` option detection
diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts
index 654d19829..a6a890137 100644
--- a/packages/astro/src/core/util.ts
+++ b/packages/astro/src/core/util.ts
@@ -151,7 +151,7 @@ export function isPage(file: URL, settings: AstroSettings): boolean {
}
export function isEndpoint(file: URL, settings: AstroSettings): boolean {
- if (!isInPagesDir(file, settings.config)) return false;
+ if (!isInPagesDir(file, settings.config) && !isInjectedRoute(file, settings)) return false;
if (!isPublicRoute(file, settings.config)) return false;
return !endsWithPageExt(file, settings) && !file.toString().includes('?astro');
}
diff --git a/packages/astro/src/vite-plugin-scanner/index.ts b/packages/astro/src/vite-plugin-scanner/index.ts
index 05889c074..945f3d8ee 100644
--- a/packages/astro/src/vite-plugin-scanner/index.ts
+++ b/packages/astro/src/vite-plugin-scanner/index.ts
@@ -82,8 +82,16 @@ async function getPageOptions(
settings: AstroSettings,
logger: Logger,
): Promise<PageOptions> {
+ const fileUrlStr = fileURL.toString();
+ const injectedRoute = settings.resolvedInjectedRoutes.find(
+ (route) => route.resolvedEntryPoint && fileUrlStr === route.resolvedEntryPoint.toString(),
+ );
+
// Run initial scan
- const pageOptions = await scan(code, id, settings);
+ const pageOptions =
+ injectedRoute?.prerender != null
+ ? { prerender: injectedRoute.prerender }
+ : await scan(code, id, settings);
// Run integration hooks to alter page options
const route: RouteOptions = {
diff --git a/packages/astro/test/fixtures/ssr-manifest/astro.config.mjs b/packages/astro/test/fixtures/ssr-manifest/astro.config.mjs
new file mode 100644
index 000000000..6a605bd77
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-manifest/astro.config.mjs
@@ -0,0 +1,22 @@
+import { defineConfig } from 'astro/config';
+import testAdapter from '../../test-adapter.js';
+import { fileURLToPath } from 'url';
+
+export default defineConfig({
+ output: 'server',
+ adapter: testAdapter(),
+ integrations: [
+ {
+ name: 'test',
+ hooks: {
+ 'astro:config:setup'({ injectRoute }) {
+ injectRoute({
+ entrypoint: fileURLToPath(new URL('./entrypoint-test.js', import.meta.url)),
+ pattern: '[...slug]',
+ prerender: true,
+ });
+ },
+ },
+ },
+ ],
+});
diff --git a/packages/astro/test/fixtures/ssr-manifest/entrypoint-test.js b/packages/astro/test/fixtures/ssr-manifest/entrypoint-test.js
new file mode 100644
index 000000000..457e89bf7
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-manifest/entrypoint-test.js
@@ -0,0 +1,9 @@
+export const prerender = true;
+
+export function getStaticPaths() {
+ return [{ params: { slug: 'test' } }];
+}
+
+export function GET() {
+ return new Response('OK — test');
+}
diff --git a/packages/astro/test/fixtures/ssr-manifest/src/pages/index.astro b/packages/astro/test/fixtures/ssr-manifest/src/pages/index.astro
deleted file mode 100644
index f189e711c..000000000
--- a/packages/astro/test/fixtures/ssr-manifest/src/pages/index.astro
+++ /dev/null
@@ -1,17 +0,0 @@
----
-import { manifest } from 'astro:ssr-manifest';
----
-<html>
- <head>
- <title>Testing</title>
- <style>
- body {
- background: green;
- }
- </style>
- </head>
- <body>
- <h1>Testing</h1>
- <div id="assets" set:html={JSON.stringify([...manifest.assets])}></div>
- </body>
-</html>
diff --git a/packages/astro/test/fixtures/ssr-manifest/src/pages/manifest.json.js b/packages/astro/test/fixtures/ssr-manifest/src/pages/manifest.json.js
new file mode 100644
index 000000000..41ae39f40
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-manifest/src/pages/manifest.json.js
@@ -0,0 +1,5 @@
+import { manifest } from 'astro:ssr-manifest';
+
+export function GET() {
+ return Response.json(manifest);
+}
diff --git a/packages/astro/test/ssr-manifest.test.js b/packages/astro/test/ssr-manifest.test.js
index eaab83468..254ea304c 100644
--- a/packages/astro/test/ssr-manifest.test.js
+++ b/packages/astro/test/ssr-manifest.test.js
@@ -1,7 +1,5 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
-import * as cheerio from 'cheerio';
-import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
describe('astro:ssr-manifest', () => {
@@ -11,27 +9,39 @@ describe('astro:ssr-manifest', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-manifest/',
- output: 'server',
- adapter: testAdapter(),
- // test suite was authored when inlineStylesheets defaulted to never
- build: { inlineStylesheets: 'never' },
});
await fixture.build();
});
it('works', async () => {
const app = await fixture.loadTestAdapterApp();
- const request = new Request('http://example.com/');
+ const request = new Request('http://example.com/manifest.json');
const response = await app.render(request);
- const html = await response.text();
-
- const $ = cheerio.load(html);
- assert.match($('#assets').text(), /\["\/_astro\/index.([\w-]{8})\.css"\]/);
+ const manifest = await response.json();
+ assert.equal(typeof manifest, 'object');
+ assert.equal(manifest.adapterName, 'my-ssr-adapter');
});
it('includes compressHTML', async () => {
const app = await fixture.loadTestAdapterApp();
+ // NOTE: `app.manifest` is actually a private property
assert.equal(app.manifest.compressHTML, true);
- assert.equal(app.manifest.compressHTML, true);
+ });
+
+ it('includes correct routes', async () => {
+ const app = await fixture.loadTestAdapterApp();
+ // NOTE: `app.manifest` is actually a private property
+
+ const manifestJsonEndpoint = app.manifest.routes.find(
+ (route) => route.routeData.route === '/manifest.json',
+ );
+ assert.ok(manifestJsonEndpoint);
+ assert.equal(manifestJsonEndpoint.routeData.prerender, false);
+
+ // There should be no route for prerendered injected routes
+ const injectedEndpoint = app.manifest.routes.find(
+ (route) => route.routeData.route === '/[...slug]',
+ );
+ assert.equal(injectedEndpoint, undefined);
});
});