Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable overrideMethod middleware by default #1069

Merged
merged 2 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/middleware/override_method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('koa-override');
1 change: 1 addition & 0 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ module.exports = appInfo => {
'siteFile',
'notfound',
'bodyParser',
'overrideMethod',
];

/**
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"co": "^4.6.0",
"debug": "^2.6.8",
"delegates": "^1.0.0",
"egg-cluster": "^1.7.0",
"egg-cluster": "^1.8.0",
"egg-cookies": "^2.2.1",
"egg-core": "^3.10.0",
"egg-development": "^1.3.1",
Expand All @@ -30,7 +30,7 @@
"egg-multipart": "^1.5.0",
"egg-onerror": "^1.4.4",
"egg-schedule": "^2.4.1",
"egg-security": "^1.10.1",
"egg-security": "^1.10.2",
"egg-session": "^2.1.1",
"egg-static": "^1.4.1",
"egg-view": "^1.1.1",
Expand All @@ -40,6 +40,7 @@
"is-type-of": "^1.0.0",
"koa-bodyparser": "^2.5.0",
"koa-is-json": "^1.0.0",
"koa-override": "^2.0.0",
"mime-types": "^2.1.15",
"sendmessage": "^1.1.0",
"urllib": "^2.22.0",
Expand All @@ -51,13 +52,13 @@
"autod-egg": "^1.0.0",
"coffee": "^3.3.2",
"egg-alinode": "^1.0.3",
"egg-bin": "^3.4.2",
"egg-bin": "^3.6.0",
"egg-doctools": "^2.0.0",
"egg-mock": "^3.7.2",
"egg-plugin-puml": "^2.4.0",
"egg-view-nunjucks": "^2.1.2",
"eslint": "^3.19.0",
"eslint-config-egg": "^4.2.0",
"eslint-config-egg": "^4.2.1",
"findlinks": "^1.1.0",
"formstream": "^1.1.0",
"glob": "^7.1.2",
Expand Down
55 changes: 55 additions & 0 deletions test/app/middleware/override_method.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

const utils = require('../../utils');

describe('test/app/middleware/override_method.test.js', () => {
let app;
before(() => {
app = utils.app('apps/override_method');
return app.ready();
});
after(() => app.close());

it('should put', () => {
app.mockCsrf();
return app.httpRequest()
.post('/test')
.send({ _method: 'PUT' })
.expect(200)
.expect('test-put');
});

it('should patch', () => {
app.mockCsrf();
return app.httpRequest()
.post('/test')
.send({ _method: 'PATCH' })
.expect(200)
.expect('test-patch');
});

it('should delete', () => {
return app.httpRequest()
.post('/test')
.send({ _method: 'DELETE' })
.expect(200)
.expect('test-delete');
});

it('should not work on PUT request', () => {
app.mockCsrf();
return app.httpRequest()
.put('/test')
.send({ _method: 'DELETE' })
.expect(200)
.expect('test-put');
});

it('should not work on GET request', () => {
return app.httpRequest()
.get('/test')
.set('x-http-method-override', 'DELETE')
.expect(200)
.expect('test-get');
});
});
17 changes: 17 additions & 0 deletions test/fixtures/apps/override_method/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = app => {
app.get('/test', function* () {
this.body = "test-get";
});

app.put('/test', function* () {
this.body = "test-put";
});

app.delete('/test', function* () {
this.body = 'test-delete';
});

app.patch('/test', function* () {
this.body = 'test-patch';
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.keys = 'foo';
3 changes: 3 additions & 0 deletions test/fixtures/apps/override_method/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "override_method"
}
3 changes: 2 additions & 1 deletion test/lib/core/loader/config_loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ describe('test/lib/core/loader/config_loader.test.js', () => {
it('should get middlewares', function* () {
app = utils.app('apps/demo');
yield app.ready();
assert.deepEqual(app.config.coreMiddleware.slice(0, 6), [
assert.deepEqual(app.config.coreMiddleware.slice(0, 7), [
'meta',
'siteFile',
'notfound',
'static',
'bodyParser',
'overrideMethod',
'session',
]);
});
Expand Down