Closed melvincarvalho closed 1 year ago
Currently, the CORS headers are set directly within the request handler like this:
res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
I suggest encapsulating this logic into a separate function, for example, called setCorsHeaders:
setCorsHeaders
function setCorsHeaders(res) { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); }
And using the function in the request handler:
setCorsHeaders(res);
No breaking changes are introduced as this refactoring is purely an internal code improvement.
Refactoring suggestion
Currently, the CORS headers are set directly within the request handler like this:
I suggest encapsulating this logic into a separate function, for example, called
setCorsHeaders
:And using the function in the request handler:
Benefits
Additional Information
No breaking changes are introduced as this refactoring is purely an internal code improvement.