summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/curvy-elephants-fry.md5
-rw-r--r--packages/astro/src/core/render-context.ts30
-rw-r--r--packages/astro/test/actions.test.js3
-rw-r--r--packages/astro/test/astro-cookies.test.js3
4 files changed, 40 insertions, 1 deletions
diff --git a/.changeset/curvy-elephants-fry.md b/.changeset/curvy-elephants-fry.md
new file mode 100644
index 000000000..41bbd9e4c
--- /dev/null
+++ b/.changeset/curvy-elephants-fry.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes an issue where Astro didn't throw an error when `Astro.rewrite` was used without providing the experimental flag
diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts
index e6ac42364..93899129d 100644
--- a/packages/astro/src/core/render-context.ts
+++ b/packages/astro/src/core/render-context.ts
@@ -147,7 +147,7 @@ export class RenderContext {
componentInstance = component;
this.isRewriting = true;
} else {
- this.pipeline.logger.warn(
+ this.pipeline.logger.error(
'router',
'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.'
);
@@ -239,6 +239,20 @@ export class RenderContext {
const rewrite = async (reroutePayload: RewritePayload) => {
pipeline.logger.debug('router', 'Called rewriting to:', reroutePayload);
+ if (!this.pipeline.manifest.rewritingEnabled) {
+ this.pipeline.logger.error(
+ 'router',
+ 'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.'
+ );
+ return new Response(
+ 'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.',
+ {
+ status: 500,
+ statusText:
+ 'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.',
+ }
+ );
+ }
const [routeData, component, newURL] = await pipeline.tryRewrite(
reroutePayload,
this.request,
@@ -433,6 +447,20 @@ export class RenderContext {
};
const rewrite = async (reroutePayload: RewritePayload) => {
+ if (!this.pipeline.manifest.rewritingEnabled) {
+ this.pipeline.logger.error(
+ 'router',
+ 'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.'
+ );
+ return new Response(
+ 'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.',
+ {
+ status: 500,
+ statusText:
+ 'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.',
+ }
+ );
+ }
pipeline.logger.debug('router', 'Calling rewrite: ', reroutePayload);
const [routeData, component, newURL] = await pipeline.tryRewrite(
reroutePayload,
diff --git a/packages/astro/test/actions.test.js b/packages/astro/test/actions.test.js
index 081e83bf6..e36d29a10 100644
--- a/packages/astro/test/actions.test.js
+++ b/packages/astro/test/actions.test.js
@@ -10,6 +10,9 @@ describe('Astro Actions', () => {
fixture = await loadFixture({
root: './fixtures/actions/',
adapter: testAdapter(),
+ experimental: {
+ rewriting: true
+ }
});
});
diff --git a/packages/astro/test/astro-cookies.test.js b/packages/astro/test/astro-cookies.test.js
index 482474b54..c27efb243 100644
--- a/packages/astro/test/astro-cookies.test.js
+++ b/packages/astro/test/astro-cookies.test.js
@@ -13,6 +13,9 @@ describe('Astro.cookies', () => {
root: './fixtures/astro-cookies/',
output: 'server',
adapter: testAdapter(),
+ experimental: {
+ rewriting: true
+ }
});
});