Hi,
I'm trying to introduce Swagger UI in our company, but since it would be running on a different server than our AppServers, I'd need to enable CORS on them.
But since we have 100+ servers, our Infra isn't very happy about it (about enabling CORS).
So I was trying to create some workaround and I think I found one, but I'd need help with the last step.
Using Fiddler I was able to create a proxy with a custom rule that headers Access-Control-Allow-Origin/Methods/Headers will be added:
static function OnBeforeResponse(oSession: Session) {
oSession.oResponse["Access-Control-Allow-Origin"] = "*";
oSession.oResponse["Access-Control-Allow-Methods"] = "GET, POST, DELETE, PUT";
oSession.oResponse["Access-Control-Allow-Headers"] = "Content-Type, x-usercontext, x-applicationname";
}
When this proxy and the rule are enabled, Swagger UI is working as expected.
When I remove this rule and leave the proxy enabled, I'll get this error message:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource...
So from my point of view, it's clear that's not working because of disabled CORS - server isn't returning those headers and therefore Swagger can't process it
Am I right?
So I was trying to add this to the shred.bundle.js file, to the function where the Response object is constructed:
response._setHeader.call(this,"Access-Control-Allow-Origin", "*");
response._setHeader.call(this,"Access-Control-Allow-Methods","GET, POST, DELETE, PUT");
response._setHeader.call(this,"Access-Control-Allow-Headers","Content-Type, x-usercontext, x-applicationName");
Although I was able to see those 3 headers in the SwaggerUI, I didn't receive any response body, HTTP code nor any other expected header.
I tried to debug and amend the script, but none of my attempts were successful, because I was always receiving empty response with HTTP status code 0.
So my questions are following:
1. Is there a way where I can add those 3 headers to the response before the response is being processed?
2. Would removing Origin and Referer request header help me? If yes, where can I amend the script so it wouldn't be adding them to the request?
3. Can I force Swagger to stop requiring those 3 headers?
I know those are quite unusual questions and it's directly against CORS settings/Same Origin Policy, but any idea, any help would really help me.
Thanks in advance
Regards,
Marek