mirror of
https://github.com/typicode/json-server.git
synced 2025-08-03 04:12:22 +08:00
Pass the link to the newly created resource in the Location header (#473)
This commit is contained in:

committed by
typicode

parent
0827ed4466
commit
ffda7238dd
@ -249,6 +249,8 @@ module.exports = (db, name) => {
|
||||
.insert(req.body)
|
||||
.value()
|
||||
|
||||
res.setHeader('Access-Control-Expose-Headers', 'Location')
|
||||
res.setHeader('Location', getFullURL(req) + '/' + resource.id)
|
||||
res.status(201)
|
||||
res.locals.data = resource
|
||||
|
||||
|
@ -506,6 +506,7 @@ describe('Server', () => {
|
||||
request(server)
|
||||
.post('/posts')
|
||||
.send({body: 'foo', booleanValue: true, integerValue: 1})
|
||||
.expect('Location', /3$/)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect({id: 3, body: 'foo', booleanValue: true, integerValue: 1})
|
||||
.expect(201)
|
||||
|
Reference in New Issue
Block a user