mperdeck/jsnlog.js

OPTIONS requests sent only

jorr opened this issue · 1 comments

jorr commented

Hi there,

I can't seem to make JSNLog work and maybe I'm missing something obvious.
I have an Angular 5 front-end and a separate API server backend in Django.
I have basically followed the instructions here: http://jsnlog.com/Documentation/HowTo/Angular2Logging
and used JL.setOptions with defaultAjaxUrl pointing to my django API endpoint. I just wanted to check what's being sent.

I then throw an error somewhere on my UI interactions to see whats going on.
But all that happens is my endpoint being hit with an endless stream of OPTIONS xhr requests. No POST is ever sent and the OPTIONS are unceasing either.

What am I doing wrong?

Late reply I guess, but if your URL is on a different server, Chrome will do a pre-flight Options request prior to letting the POST go. You need to respond to it. If you want any cross-domain Options request to pass, just add these headers to the options response on the server side:

response.addHeader("Access-Control-Allow-Origin", "*")
response.addHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Methods, Access-Control-Allow-Credentials, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, authorization, remoteServer, service, section, username, password, X-QueryName, X-Crud, X-Section, jsnlog-requestid"); 

And the request should pass. You'd do this in whatever the end point handler is on the server. in Java you'd override the doOptions() method on a HttpServlet for example.