Pass the link to the newly created resource in the Location header (#473)

This commit is contained in:
Jonathan Gautheron
2017-02-13 20:25:10 +01:00
committed by typicode
parent 0827ed4466
commit ffda7238dd
2 changed files with 3 additions and 0 deletions

View File

@ -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

View File

@ -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)