Skip to content

Commit

Permalink
feat: remove support for old API routes syntax (#7822)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Aug 8, 2023
1 parent 9a01cc6 commit 7d2f311
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-dancers-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': major
---

Removed support for old syntax of the API routes.
27 changes: 1 addition & 26 deletions packages/astro/src/runtime/server/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function renderEndpoint(
ssr: boolean,
logging: LogOptions
) {
const { request, params } = context;
const { request } = context;

const chosenMethod = request.method?.toUpperCase();
const handler = getHandlerFromModule(mod, chosenMethod, logging);
Expand All @@ -68,35 +68,10 @@ ${chosenMethod} requests are not available when building a static site. Update y
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, {
get(target, prop) {
if (prop in target) {
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 {
return undefined;
}
Expand Down

0 comments on commit 7d2f311

Please sign in to comment.