There is at least one middleware on npm for handling CORS in Express: cors. [see @mscdex answer]
This is how to set custom response headers, from the ExpressJS DOC
res.set(field, [value])
Set header field to value
res.set('Content-Type', 'text/plain');
or pass an object to set multiple fields at once.
res.set({
'Content-Type': 'text/plain',
'Content-Length': '123',
'ETag': '12345'
})
Aliased as
res.header(field, [value])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…