diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index dd278ae5a..73c13c139 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -470,7 +470,7 @@ export async function renderEndpoint(mod: EndpointHandler, request: Request, par ); } - if(handler.length > 1) { + 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: @@ -479,19 +479,19 @@ export function get({ params, request }) { //... } -Update your code to remove this warning.`) +Update your code to remove this warning.`); } const context = { request, - params + params, }; const proxy = new Proxy(context, { get(target, prop) { - if(prop in target) { + if (prop in target) { return Reflect.get(target, prop); - } else if(prop in params) { + } else if (prop in params) { // 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: @@ -505,7 +505,7 @@ Update your code to remove this warning.`); } else { return undefined; } - } + }, }) as APIContext & Params; return await handler.call(mod, proxy, request); diff --git a/packages/astro/test/api-routes.test.js b/packages/astro/test/api-routes.test.js index d7d0c3d29..80fb0970d 100644 --- a/packages/astro/test/api-routes.test.js +++ b/packages/astro/test/api-routes.test.js @@ -15,19 +15,19 @@ describe('API routes', () => { const one = JSON.parse(await fixture.readFile('/old-api/twoarg/one.json')); expect(one).to.deep.equal({ param: 'one', - pathname: '/old-api/twoarg/one.json' + pathname: '/old-api/twoarg/one.json', }); const two = JSON.parse(await fixture.readFile('/old-api/twoarg/two.json')); expect(two).to.deep.equal({ param: 'two', - pathname: '/old-api/twoarg/two.json' + pathname: '/old-api/twoarg/two.json', }); }); it('param first argument is supported', async () => { const one = JSON.parse(await fixture.readFile('/old-api/onearg/one.json')); expect(one).to.deep.equal({ - param: 'one' + param: 'one', }); }); }); @@ -37,7 +37,7 @@ describe('API routes', () => { const one = JSON.parse(await fixture.readFile('/context/data/one.json')); expect(one).to.deep.equal({ param: 'one', - pathname: '/context/data/one.json' + pathname: '/context/data/one.json', }); }); });