Skip to content

Commit ffda723

Browse files
jgautherontypicode
authored andcommitted
Pass the link to the newly created resource in the Location header (typicode#473)
1 parent 0827ed4 commit ffda723

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/server/router/plural.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ module.exports = (db, name) => {
249249
.insert(req.body)
250250
.value()
251251

252+
res.setHeader('Access-Control-Expose-Headers', 'Location')
253+
res.setHeader('Location', getFullURL(req) + '/' + resource.id)
252254
res.status(201)
253255
res.locals.data = resource
254256

test/server/plural.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ describe('Server', () => {
506506
request(server)
507507
.post('/posts')
508508
.send({body: 'foo', booleanValue: true, integerValue: 1})
509+
.expect('Location', /3$/)
509510
.expect('Content-Type', /json/)
510511
.expect({id: 3, body: 'foo', booleanValue: true, integerValue: 1})
511512
.expect(201)

0 commit comments

Comments
 (0)