I’m developing a web-based dashboard, which populates various HTML tables with JSON data returned from calling Workflow Processes. I’ve done this frequently in the past, using the HTTP Server Input.
The web front-end uses a Javascript “setInterval” function to re-run the Workflow process that serves the JSON via an AJAX call:
This all works fine when using the HTTP Server Input.
However, when I use the NodeJS Server Input, set to require Authentication, each subsequent AJAX call fails to respect the session authentication (the initial call works), and so the AJAX call fails (it doesn’t run, so doesn’t produce JSON, so I get errors thrown).
How do I get NodeJS to send in the proper authorization header and the authenticated Username for the current session when making AJAX reload() requests?
<html>
<body>
<h1>This is a static title</h1>
<hr>
<div id="mydiv">
<p>Dynamic value: <b>%u</b></p>
</div>
<hr>
<h1>This is a static footer</h1>
<script>
setInterval( function () {
let xhr=new XMLHttpRequest();
xhr.open("GET","/refresh",false);
xhr.send();
document.getElementById("mydiv").innerHTML = xhr.responseText;
}, 3000 );
</script>
</body>
</html>
This page is delivered by Workflow through an endpoint named /firsttime. The first time I call it, I am asked to authenticate. Once received by the browser, the page automatically refreshes itself by repeatedly calling the /refresh endpoint (it’s the same Workflow process that monitors both endpoints). When /refresh is called, it replies simply with:
<p>Dynamic value: <b>%u</b></p>
(in both cases, %u is dynamically replaced by Workflow with a unique value).
As expected, I don’t need to authenticate with each refresh request.
And I do receive the expected chunk of HTML.
Check your browser’s console and see what kind of error gets sent back. I suspect it might have to do with a Cross-Origin issue (e.g. when you fetch your main page from a URL domain, and then request updates from a different URL domain).
Also, I’m not quite sure how DataTables (which seems to be what you’re using) handles the ajax requests, it could be an issue specific to the library.
Yes. it could be a Datatables.net issue. I’m using their ajax “reload()” method, and the error thrown is that the JSON file is invalid. Which it is, because it isn’t the JSON file the browser receives, it’s getting the NodeJS default login page back. Because the reload() method, for some reason, isn’t sending the session data/cookies set by the NodeJS authentication.
But I don’t know enough to being to phrase correct questions about this. What does the OL NodeJS implementation use for authentication? I see lots of references when I do web searches to “Passport” and “Express” for authentication libraries.