Skip to content

Commit

Permalink
fix(koa): Use extended query parser for compatibility (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jun 23, 2021
1 parent 6584a21 commit b2944ba
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 351 deletions.
551 changes: 273 additions & 278 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/authentication-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"@feathersjs/rest-client": "^5.0.0-pre.4",
"@feathersjs/socketio": "^5.0.0-pre.4",
"@feathersjs/socketio-client": "^5.0.0-pre.4",
"@types/debug": "^4.1.5",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
"axios": "^0.21.1",
Expand Down
1 change: 0 additions & 1 deletion packages/authentication-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"devDependencies": {
"@feathersjs/memory": "^5.0.0-pre.4",
"@types/bcryptjs": "^2.4.2",
"@types/debug": "^4.1.5",
"@types/lodash": "^4.14.170",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
Expand Down
1 change: 0 additions & 1 deletion packages/authentication-oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
},
"devDependencies": {
"@feathersjs/memory": "^5.0.0-pre.4",
"@types/debug": "^4.1.5",
"@types/express": "^4.17.12",
"@types/express-session": "^1.17.3",
"@types/lodash": "^4.14.170",
Expand Down
1 change: 0 additions & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
},
"devDependencies": {
"@feathersjs/memory": "^5.0.0-pre.4",
"@types/debug": "^4.1.5",
"@types/lodash": "^4.14.170",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
Expand Down
1 change: 0 additions & 1 deletion packages/configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"config": "^3.3.6"
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
"mocha": "^8.4.0",
Expand Down
11 changes: 6 additions & 5 deletions packages/koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,22 @@
"access": "public"
},
"dependencies": {
"@types/koa": "^2.13.3",
"@types/koa-bodyparser": "^4.3.1",
"@types/koa-qs": "^2.0.0",
"@feathersjs/authentication": "^5.0.0-pre.4",
"@feathersjs/commons": "^5.0.0-pre.4",
"@feathersjs/errors": "^5.0.0-pre.4",
"@feathersjs/transport-commons": "^5.0.0-pre.4",
"koa": "^2.13.1",
"koa-bodyparser": "^4.3.0"
"koa-bodyparser": "^4.3.0",
"koa-qs": "^3.0.0"
},
"devDependencies": {
"@feathersjs/memory": "^5.0.0-pre.4",
"@feathersjs/authentication-local": "^5.0.0-pre.4",
"@feathersjs/feathers": "^5.0.0-pre.4",
"@feathersjs/memory": "^5.0.0-pre.4",
"@feathersjs/tests": "^5.0.0-pre.4",
"@types/debug": "^4.1.5",
"@types/koa": "^2.13.3",
"@types/koa-bodyparser": "^4.3.1",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
"mocha": "^8.4.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/koa/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Debug from 'debug';
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import koaQs from 'koa-qs';
import { Application as FeathersApplication } from '@feathersjs/feathers';
import { routing } from '@feathersjs/transport-commons';
import { createDebug } from '@feathersjs/commons';

import { Application } from './declarations';
import { errorHandler } from './error-handler';

const debug = Debug('@feathersjs/koa');
const debug = createDebug('@feathersjs/koa');

export * from './declarations';
export * from './authenticate';
Expand Down Expand Up @@ -68,6 +69,7 @@ export function koa (_app?: FeathersApplication): Application<any> {
}
});

koaQs(app as any);
app.configure(routing());
app.use((ctx, next) => {
ctx.feathers = { provider: 'rest' };
Expand Down
2 changes: 1 addition & 1 deletion packages/koa/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FeathersKoaContext } from './declarations';

const debug = createDebug('@feathersjs/koa:rest');

export function rest (){
export function rest () {
return async (ctx: FeathersKoaContext, next: Next) => {
const { app, request } = ctx;
const { query: koaQuery, path, body: data, method: httpMethod } = request;
Expand Down
8 changes: 7 additions & 1 deletion packages/koa/test/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ describe('@feathersjs/koa/authentication', () => {
it('can make a protected request with Authorization header', async () => {
const { accessToken } = authResult;

const { data } = await axios.get('/dummy/dave', {
const { data } = await axios.get('/dummy/dave?user[name]=thing&user[message]=hi', {
headers: {
Authorization: accessToken
}
});

assert.strictEqual(data.id, 'dave');
assert.deepStrictEqual(data.params.query, {
user: {
name: 'thing',
message: 'hi'
}
});
assert.deepStrictEqual(data.params.user, user);
assert.strictEqual(data.params.authentication.accessToken, accessToken);
});
Expand Down
5 changes: 2 additions & 3 deletions packages/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@
"access": "public"
},
"dependencies": {
"@types/axios": "^0.14.0",
"@types/lodash": "^4.14.170",
"axios": "^0.21.1",
"lodash": "^4.17.21"
},
"devDependencies": {
"@feathersjs/feathers": "^5.0.0-pre.4",
"@types/axios": "^0.14.0",
"@types/debug": "^4.1.5",
"@types/lodash": "^4.14.170",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
"mocha": "^8.4.0",
Expand Down
101 changes: 46 additions & 55 deletions packages/tests/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,90 @@ import { verify } from './fixture';

export function restTests (description: string, name: string, port: number) {
describe(description, () => {
it('GET .find', () => {
return axios.get(`http://localhost:${port}/${name}`)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.find(res.data);
});
it('GET .find', async () => {
const res = await axios.get(`http://localhost:${port}/${name}`);

assert.ok(res.status === 200, 'Got OK status code');
verify.find(res.data);
});

it('GET .get', () => {
return axios.get(`http://localhost:${port}/${name}/dishes`)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.get('dishes', res.data);
});
it('GET .get', async () => {
const res = await axios.get(`http://localhost:${port}/${name}/dishes`);

assert.ok(res.status === 200, 'Got OK status code');
verify.get('dishes', res.data);
});

it('POST .create', () => {
it('POST .create', async () => {
const original = {
description: 'POST .create'
};

return axios.post(`http://localhost:${port}/${name}`, original)
.then(res => {
assert.ok(res.status === 201, 'Got CREATED status code');
verify.create(original, res.data);
});
const res = await axios.post(`http://localhost:${port}/${name}`, original);

assert.ok(res.status === 201, 'Got CREATED status code');
verify.create(original, res.data);
});

it('PUT .update', () => {
it('PUT .update', async () => {
const original = {
description: 'PUT .update'
};

return axios.put(`http://localhost:${port}/${name}/544`, original)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.update('544', original, res.data);
});
const res = await axios.put(`http://localhost:${port}/${name}/544`, original);

assert.ok(res.status === 200, 'Got OK status code');
verify.update('544', original, res.data);
});

it('PUT .update many', () => {
it('PUT .update many', async () => {
const original = {
description: 'PUT .update',
many: true
};

return axios.put(`http://localhost:${port}/${name}`, original)
.then(res => {
const { data } = res;
assert.ok(res.status === 200, 'Got OK status code');
verify.update(null, original, data);
});
const res = await axios.put(`http://localhost:${port}/${name}`, original);
const { data } = res;

assert.ok(res.status === 200, 'Got OK status code');
verify.update(null, original, data);
});

it('PATCH .patch', () => {
it('PATCH .patch', async () => {
const original = {
description: 'PATCH .patch'
};

return axios.patch(`http://localhost:${port}/${name}/544`, original)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.patch('544', original, res.data);
});
const res = await axios.patch(`http://localhost:${port}/${name}/544`, original);

assert.ok(res.status === 200, 'Got OK status code');
verify.patch('544', original, res.data);
});

it('PATCH .patch many', () => {
it('PATCH .patch many', async () => {
const original = {
description: 'PATCH .patch',
many: true
};

return axios.patch(`http://localhost:${port}/${name}`, original)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.patch(null, original, res.data);
});
const res = await axios.patch(`http://localhost:${port}/${name}`, original);

assert.ok(res.status === 200, 'Got OK status code');
verify.patch(null, original, res.data);
});

it('DELETE .remove', () => {
return axios.delete(`http://localhost:${port}/${name}/233`)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.remove('233', res.data);
});
it('DELETE .remove', async () => {
const res = await axios.delete(`http://localhost:${port}/${name}/233`)

assert.ok(res.status === 200, 'Got OK status code');
verify.remove('233', res.data);
});

it('DELETE .remove many', () => {
return axios.delete(`http://localhost:${port}/${name}`)
.then(res => {
assert.ok(res.status === 200, 'Got OK status code');
verify.remove(null, res.data);
});
it('DELETE .remove many', async () => {
const res = await axios.delete(`http://localhost:${port}/${name}`);

assert.ok(res.status === 200, 'Got OK status code');
verify.remove(null, res.data);
});
});
}
1 change: 0 additions & 1 deletion packages/transport-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
},
"devDependencies": {
"@feathersjs/feathers": "^5.0.0-pre.4",
"@types/debug": "^4.1.5",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.1",
"mocha": "^8.4.0",
Expand Down

0 comments on commit b2944ba

Please # to comment.