Michele De Chiffre · Mar 11, 2021

CORS in REST service when using Maps

I'm trying to setup a REST server with CORS support. I have created a class that handles a specific part of the service (printer control). This class I have referenced in my main REST class by adding <Map Prefix="/print" Forward="myClass.PrintAPI" />

My main class does have its own <Route>s and handles CORS requests perfectly. But in my subclass OnHandleCorsRequest() is only run when requesting from same origin and never run when making a CORS request. I have set Parameter HandleCorsRequest = "true" in both my main REST class and the subclass.


Can anyone point me in the right direction on what might be the problem or which alternative methods I should use and run?

Product version: IRIS 2020.2
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2020.2 (Build 211U) Fri Jun 26 2020 13:48:12 EDT
3 1 4 104
Log in or sign up to continue


When I had problems with Cors I use overload of methods in my SuperClass to solve this problem.

ClassMethod HandleDefaultCorsRequest(pUrl As %String) As %Status [ Private ]
    Do %response.SetHeader("Access-Control-Allow-Origin","*")
    Do %response.SetHeader("Access-Control-Allow-Credentials","true")
    Do %response.SetHeader("Access-Control-Allow-Methods","GET, PUT, POST, DELETE, PATCH, OPTIONS")
    Do %response.SetHeader("Access-Control-Allow-Headers","Access-Control-*, Content-Type, Authorization, Accept, Accept-Language, X-Requested-With, Origin")
    Quit $$$OK

Thanks for your answer. From which method would you then call HandleDefaultCors? That is, should I only define HandleDefaultCors in my superclass and then use OnHandleCorsRequest in my subclasses?

OnHandleCorsRequest is called automatically if a browser requests CORS.

To add to original answer a bit:

Do %response.SetHeader("Access-Control-Allow-Origin","*")

This is OK for development but for production use you need to replace * with a hostname of your web site.