mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
fix: check experimental flag when using the rewrite function (#11349)
* fix: check experimental flag when using the rewrite function * apply feedback
This commit is contained in:
parent
d7ae91c83c
commit
98d9ce41f2
4 changed files with 40 additions and 1 deletions
5
.changeset/curvy-elephants-fry.md
Normal file
5
.changeset/curvy-elephants-fry.md
Normal file
|
@ -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
|
|
@ -147,7 +147,7 @@ export class RenderContext {
|
||||||
componentInstance = component;
|
componentInstance = component;
|
||||||
this.isRewriting = true;
|
this.isRewriting = true;
|
||||||
} else {
|
} else {
|
||||||
this.pipeline.logger.warn(
|
this.pipeline.logger.error(
|
||||||
'router',
|
'router',
|
||||||
'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.'
|
'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) => {
|
const rewrite = async (reroutePayload: RewritePayload) => {
|
||||||
pipeline.logger.debug('router', 'Called rewriting to:', reroutePayload);
|
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(
|
const [routeData, component, newURL] = await pipeline.tryRewrite(
|
||||||
reroutePayload,
|
reroutePayload,
|
||||||
this.request,
|
this.request,
|
||||||
|
@ -433,6 +447,20 @@ export class RenderContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
const rewrite = async (reroutePayload: RewritePayload) => {
|
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);
|
pipeline.logger.debug('router', 'Calling rewrite: ', reroutePayload);
|
||||||
const [routeData, component, newURL] = await pipeline.tryRewrite(
|
const [routeData, component, newURL] = await pipeline.tryRewrite(
|
||||||
reroutePayload,
|
reroutePayload,
|
||||||
|
|
|
@ -10,6 +10,9 @@ describe('Astro Actions', () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/actions/',
|
root: './fixtures/actions/',
|
||||||
adapter: testAdapter(),
|
adapter: testAdapter(),
|
||||||
|
experimental: {
|
||||||
|
rewriting: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@ describe('Astro.cookies', () => {
|
||||||
root: './fixtures/astro-cookies/',
|
root: './fixtures/astro-cookies/',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
adapter: testAdapter(),
|
adapter: testAdapter(),
|
||||||
|
experimental: {
|
||||||
|
rewriting: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue