0

I have written a javascript web app for document processing. I now desire to hit some web services such as NLTK-server, TIKA-server, and SOLR, for additional processing.

I am able to hit the REST endpoints of all these using curl, but trying to move to javascript/jquery/Ajax I ran into the same-origin (CORS) problem that many have asked about here. It seems the solution is setting up a reverse proxy, and while I understand the concept, the searches I've done provide results that are way over my head. As common as this problem must be (Web apps hitting web services), I have to think that there must be a simple solution. I'm a developer, not a sys admin and reading how to set up Jetty (For example) as a reverse proxy is an exercise in frustration. Would appreciate if someone could point me to a "Proxy 101" tutorial, as my google-fu has come up short.

**************EDIT************************

I'm developing in Netbeans (I know it's overkill but been using it for years and am comfortable with it) with the embedded GlassFish server. So when executed, I'm running localhost:8383. As for the "Services" I'm hitting, I run:

java -jar tika-server

and it starts up the tika-server listening on port 9998 (also on localhost) and I'm able to submit/retrieve docs using curl. However, when I submit a document to Tika via ajax, I get the CORS error. I was able to hit the SOLR server, but only because I modified the AJAX request to include:

wt:'json'

because Solr supports JSONP. However, I can not assume that every web service I want to hit supports JSONP. I'm using Tika to extract text from .pdfs, .docx ... I've done so in the past when writing Java code, and just including the jar, but trying to move to a web front end is proving difficult.

GeoffWillis
  • 113
  • 2
  • 13
  • can you add what is your backend server? – Shyam Babu Sep 21 '17 at 20:09
  • Can you please format your question in paragraphs? it will improve readability. – rdarioduarte Sep 21 '17 at 20:26
  • This is the wrong place to ask for a recommendation for a product that fullfils your somewhat unspecified requirements. If you are trying to setup the proxy and need well educated help show what you tried. – blafasel Sep 21 '17 at 20:26
  • A public open CORS proxy might fit your needs. For code examples and an explanation, see the *How to use a CORS proxy to get around “No Access-Control-Allow-Origin header” problems* section of the answer at *https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141* – sideshowbarker Sep 22 '17 at 00:01
  • Thanks for the post, I'm still reading the link provided (Which led to other links...) will return after understanding the pre-flight topic and the proxy discussion. Appreciate the answer and am taking the time to digest before posting follow on questions. – GeoffWillis Sep 25 '17 at 17:53

1 Answers1

1

You can solve the cors problem with a single line of code. Say you want to enable requests from http://localhost:3000.

java -jar tika-server --cors http://localhost:3000

That's it.