Dr.Knowitall Dr.Knowitall - 1 year ago 134
Javascript Question

How can I set response header on express.js assets

I need to set CORS to be enabled on scripts served by express. How can I set the headers in these returned responses for public/assets?

Answer Source

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.

  'Content-Type': 'text/plain',
  'Content-Length': '123',
  'ETag': '12345'

Aliased as

res.header(field, [value])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download