feat: remove support for old API routes syntax (#7822)
This commit is contained in:
parent
9a01cc64c2
commit
7d2f311d42
2 changed files with 6 additions and 26 deletions
5
.changeset/mighty-dancers-lay.md
Normal file
5
.changeset/mighty-dancers-lay.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': major
|
||||||
|
---
|
||||||
|
|
||||||
|
Removed support for old syntax of the API routes.
|
|
@ -45,7 +45,7 @@ export async function renderEndpoint(
|
||||||
ssr: boolean,
|
ssr: boolean,
|
||||||
logging: LogOptions
|
logging: LogOptions
|
||||||
) {
|
) {
|
||||||
const { request, params } = context;
|
const { request } = context;
|
||||||
|
|
||||||
const chosenMethod = request.method?.toUpperCase();
|
const chosenMethod = request.method?.toUpperCase();
|
||||||
const handler = getHandlerFromModule(mod, chosenMethod, logging);
|
const handler = getHandlerFromModule(mod, chosenMethod, logging);
|
||||||
|
@ -68,35 +68,10 @@ ${chosenMethod} requests are not available when building a static site. Update y
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove support for old API in Astro 3.0
|
|
||||||
if (handler.length > 1) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(`
|
|
||||||
API routes with 2 arguments have been deprecated. Instead they take a single argument in the form of:
|
|
||||||
|
|
||||||
export function get({ params, request }) {
|
|
||||||
//...
|
|
||||||
}
|
|
||||||
|
|
||||||
Update your code to remove this warning.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const proxy = new Proxy(context, {
|
const proxy = new Proxy(context, {
|
||||||
get(target, prop) {
|
get(target, prop) {
|
||||||
if (prop in target) {
|
if (prop in target) {
|
||||||
return Reflect.get(target, prop);
|
return Reflect.get(target, prop);
|
||||||
} else if (prop in params) {
|
|
||||||
// TODO: Remove support for old API in Astro 3.0
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn(`
|
|
||||||
API routes no longer pass params as the first argument. Instead an object containing a params property is provided in the form of:
|
|
||||||
|
|
||||||
export function get({ params }) {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
Update your code to remove this warning.`);
|
|
||||||
return Reflect.get(params, prop);
|
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue