Problems when enabling CORS!!

685 views
Skip to first unread message

michael.hi...@gmail.com

unread,
Mar 31, 2017, 11:13:42 AM3/31/17
to cornerstone platform
I'm using node js and my application runs on port 3000 and DCM4CHEE with the WADO service runs on port 8080 and at the time of running cornerstone the browser shows this 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 acces

But I tried to enable the cors in NODEJS but it does not work me install mendiate npm cors but still does not work also use the proxy of cors-anywhere.herokuapp.com

And I keep the code this

If (series.numberOfFrames! == undefined) {
  Var numberOfFrames = series.numberOfFrames;
  For (var i = 0; i <numberOfFrames; i ++) {
  Var imageId = series.instanceList [0] .imageId + "? Frame =" + i;
  If (imageId.substr (0, 4)! == 'http') {
  ImageId = "dicomweb: https: //cors-anywhere.herokuapp.com/http: // localhost: 8080 /" + imageId;
  }
  Stack.imageIds.push (imageId);
  }


Or I have to enable the CORS from DCM4CHEE and if that's how it is done, please I need help

Leonardo Campos

unread,
Apr 1, 2017, 12:17:13 AM4/1/17
to michael.hi...@gmail.com, cornerstone platform
Have you tried using a reverse proxy?
Nginx is a good one. (Orthanc example)
It's easy to set up and very light and fast.

----

I suppose cors-anywhere is not working because you're passing localhost as host but it will always be resolved to 127.0.0.1 and the cors-anywhere will not be able to reach your node server. You should use a valid host name (try using a DDNS) or IP address. The IP address can't be any private IP address (127.0.0.1, 192.168.*.*, 172.16.*.* or 10.*.*.*).

----

If you're using nodejs you can also take a look at this code:
https://github.com/OHIF/Viewers/tree/master/Packages/ohif-wadoproxy/server

OHIF doesn't send requests directly to DICOM servers. It sends the request to its wado proxy that's under the same domain.

OHIF (browser) <-> OHIF (server, wado proxy) <-> Orthanc / DCM4CHEE / etc

If you go to http://viewer.ohif.org/ and open Chrome Dev Tools you'll see requests like this:


I hope this help you.

Regards,

Leonardo Campos
Minas Gerais, Brazil


--
You received this message because you are subscribed to the Google Groups "cornerstone platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cornerstone-platform+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cornerstone-platform/af03e9de-91d4-49e5-b403-e40b3a72c660%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

michael.hi...@gmail.com

unread,
Apr 1, 2017, 11:33:26 AM4/1/17
to cornerstone platform, michael.hi...@gmail.com
To this Nginx you mean?


Try to use reverse proxy but I could not, you can explain more

This is what the browser shows me

The server responds with the following;

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

Also try using api proxy https://cors-anywhere.herokuapp.com/
But it does not work

These are my app.js code

Var express = require ('express');
Var cors = require ('cors')
Var users = require ('./ routes / users');
Var app = express ();
App.use (cors ({origin: 'localhost: 8080';}));
App.set ('views', path.join (__ dirname, 'views'));
App.use ('/', index); App.use ('/ users', users); App.listen (3000, function () {}); Module.exports = app

Can you explain me more
Also try to enter the page http://viewer.ohif.org/ but this fall; Can you explain me more how to use a reverse proxy in NODEJS because I try to use one and I could not

I also saw this example

Var http = require ('http'),
    HttpProxy = require ('http-proxy');

Var proxy = httpProxy.createProxyServer ({target: 'http: // localhost: 8042'}) .listen (8000);

Proxy.on ('proxyRes', function (proxyReq, req, res, options) {
  // add the CORS header to the response
  Res.setHeader ('Access-Control-Allow-Origin', '*');
});

Proxy.on ('error', function (e) {
  // suppress errors
});

But I did not work because I use express.
Reply all
Reply to author
Forward
0 new messages