Tuesday, 4 April 2017

How to use Reverse Proxy and enable CORS with NGINX?

I'm programming in NODEJS with cornerstone sdk which is a DICOM viewer

Here is the link

Https://www.npmjs.com/package/cornerstone-wado-image-loader 

And I'm running my NODEJS application on port 3000 to get the dicom of DCM4CHEE WADO service as follows

Http: // localhost: 3333 / wado? RequestType = WADO & studyUID = 1.3.6.1.4.1.25403.166563008443.5076.20120418075541.1 & seriesUID = 1.3.6.1.4.1.25403.166563008443.5076.20120418075541.2 & objectUID = 1.3.6.1.4.1.25403.166563008443.5076.20120418075557. 1 & contentType = application% 2Fdicom & transferSyntax = 1.2.840.10008.1.2.1 

But the browser shows me the following error

XMLHttpRequest can not load http: // localhost: 8080 / wado? RequestType = WADO & studyUID = 1.2.840.113704.1.111.5 ... 26513.429 & contentType = application% 2Fdicom & transferSyntax = 1.2.840.10008.1.2. In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost: 3000' is therefore not allowed access. 

Then in the documentation says that you have to use reverse proxy and enable CORS for that INSTAL NGINX

And this is my NGINX configuration

Server { 

        Listen 80; 
        Server_name localhost; 

        Location / { 
            Proxy_pass http: // localhost: 3000; 
            Proxy_set_header HOST $ host; 
            Proxy_set_header X-Real-IP $ remote_addr; 
            Rewrite /o(.*) $ 1 break; 
            Add_header 'Access-Control-Allow-Credentials' 'true'; 
            Access-Control-Allow-Headers '' DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-$ 
            Add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 
            Add_header 'Access-Control-Allow-Origin' '*'; 

        } 
     }

But the browser still displays the error

XMLHttpRequest can not load http: // localhost: 8080 / wado? RequestType = WADO & studyUID = 1.2.840.113704.1.111.5 ... 26513.429 & contentType = application% 2Fdicom & transferSyntax = 1.2.840.10008.1.2. In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http: // localhost' is therefore not allowed access. 

HEADER RESPONSE

Content-Type: application / dicom 
Date: Sat, 01 Apr 2017 01:15:38 GMT 
Expires: 0 
Server: Apache-Coyote / 1.1 
Transfer-Encoding: chunked 
X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag = JBoss_4_2_3_GA 
Date = 200807181439) /JBossWeb-2.0 

REQUEST HEADER

Accept: * / * 
Accept-Encoding: gzip, deflate, sdch, br 
Accept-Language: en-US, en, q = 0.8, en-US; q = 0.6, en; q = 0.4 
Connection: keep-alive 
Host: localhost: 8080 
Origin: http: // localhost: 3000 
Referer: http: // localhost: 3000 / 
User-Agent: Mozilla / 5.0 (X11; Linux x86_64) AppleWebKit / 537.36 (KHTML, like 
Gecko) Chrome / 55.0.2883.87 Safari / 537.36 

As I do to enable the CORS in port 8080 where it is dcm4chee with WADO to get the DICOM?

I'm sorry for my English



via M. Node

No comments:

Post a Comment