× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



It looks like req.url contains a forward slash and the query string from the URL, but not the hostname.


From: Justin Taylor
Sent: Monday, January 15, 2018 12:40 PM
To: OpenSource-Midrange. com (opensource@xxxxxxxxxxxx) <opensource@xxxxxxxxxxxx>
Subject: Node Access-Control-Allow-Origin

I'm trying to call a Node webservice from an existing app running on Apache. It's giving me problems because the app is running on a different port than Node. I did some searching, and I was able to get it to work by adding a new property to my header response:
res.writeHead(200, {
'Content-Type' : 'application/json'
, 'Access-Control-Allow-Origin' : 'http://myHostName:80' // Added this line
});

The trouble is that I have multiple production and test Apache servers, and I don't want to hardcode them all. They all have the same hostname, but I can't find a way to do a wildcard for the port#. What I got from Google, was to manually match against the calling host. If it matches, simply parrot it back for the Access-Control-Allow-Origin. The example I found returns null for me for the calling host. Here's what I found:
console.log(url.parse(req.url, true).host); //should return 'myHostName:80', but I get null



TIA

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.