-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable overrideMethod middleware by default (#1069)
- Loading branch information
1 parent
bfb8df5
commit a4ba2a2
Showing
8 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('koa-override'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,6 +254,7 @@ module.exports = appInfo => { | |
'siteFile', | ||
'notfound', | ||
'bodyParser', | ||
'overrideMethod', | ||
]; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.keys = 'foo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "override_method" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters