Modify Response Headers in Angular Proxy

Angular includes the ability to proxy requests to back-end servers. This feature can also be used to modify responses.

To modify responses, create proxy.conf.js in the src folder, then add an entry to modify the response headers:

module.exports = {
	"/path/**": {
		secure: false,
		bypass: function(req, res, opts) {
			res.setHeader("x-your-header", "value");
		}
	}
}

Now, after you run ng server --proxy-config src/proxy.config.js requests to /path will contain the header.

A common application of this approach is to set CORS headers when the Angular dev server is hosting scripts that can be loaded from other applications.

Broader Topics Related to Modify Response Headers in Angular Proxy (ng serve)

Angular (TypeScript Framework)

Learn Angular

Modify Response Headers in Angular Proxy (ng serve) Knowledge Graph