· May 15, 2023

EnsLib.HL7.Service.HTTPService - enable CORS

I have a production with a HLv2 HTTP Listener.
For demo purposes, I need to send HL7 messages directly from a browser. Here is an example (React/typescript):

const message = "MSH...";
const args: RequestInit = {
      method: "POST",
      mode: "no-cors",
      body: message

const response = await fetch(IRIS_SERVER_HL7_HTTP, args);
// await checkResponseAsync(response);
return await response.text();

Technically it works, and Chrome network monitor lets me know that operation completes successfully (response code is 200 and I see the ACK), but the browser restricts fetching the response text because IRIS doesn't send the 'Access-Control-Allow-Origin: *' header. How could I add that header to the EnsLib.HL7.Service.HTTPService response?

Product version: IRIS 2023.1
Discussion (1)0
Log in or sign up to continue

Here it is:

Class MyHL7HTTPService Extends EnsLib.HL7.Service.HTTPService

Method OnAdapterHTTPResponse(
    ByRef pStatus As %Status,
    ByRef pHTTPResponseStatus As %String,
    ByRef pBodyLen As %Integer,
    ByRef pResponseBodyStream As %Stream.Object,
    ByRef pMainResponseHeader As %String,
    ByRef pHeaderExtra As %String)
    set pHeaderExtra = pHeaderExtra _ "Access-Control-Allow-Origin: *"_ $char(13) _ $char(10) 
                                    _ "Access-Control-Allow-Headers: *" _ $char(13) _ $char(10) 
                                    _ "Access-Control-Allow-Methods: *" _ $char(13) _ $char(10)