I have a node.js server using socket.io. The idea is to allow two different html files to communicate information to each other through this server. All was well with socket.io ver0.9.16 until ver 1.0 came out. Now, I receive a few errors on both the client and server side, the most apparent (to me, since I am new to this) is the ERR_NAME_NOT_RESOLVED error that I find when I start up the locally hosted server.js file and attempt to connect to it through the client html.
When I open the console in Google Chrome, I find this error which prints again to the console every second or so:
GET http://file/socket.io/?EIO=2&transport=polling&t=1406247171961-0 net::ERR_NAME_NOT_RESOLVED
What follows are snippets of places where I may have problems in my html and server.js files as well as in a js file that is used by my html file to connect to the server.
index.html
I think this bit of code gets the socket.io client code from the localhost server. This is the first place where I may think that I have a problem
<script src="http://localhost:4000/socket.io/socket.io.js "></script>
In addition, the following is where I import my index.js file which is used to connect to the server
<script type="text/javascript" src="scriptsTeacher.js" ></script>
-
server.js
This code (according to my sources) should set up a server on the localhost with port 4000 to which clients can connect and send/receive information
var io;
io = require('socket.io').listen(4000);
io.on('connection', function(socket)
{
console.log("user connected");
});
-
index.js
This code is used by the index.html which has it connect to a server listening on port 4000 using socket.io.
var socket = io.connect('localhost:4000');
-
Currently, there are two blatant errors that I can find. They are probably not the root of the problem, but they are as far as my limited debugging experience can take me.
ERR_NAME_NOT_RESOLVED: (NOTE: I have looked at socket.io ERR_NAME_NOT_RESOLVED and it was not entirely useful since that user had a typo by using http:\\ instead of http://). As stated before, when opening index.html in Google Chrome and accessing the console, I receive multiple ERR_NAME_NOT_RESOLVED errors.
There is no "Welcome to socket.io" message when accessing localhost:4000 I am certain that there should be such a message. Note that there is no 404 error, when I start up the server, I can access that webpage, but it is blank. If the server is not running, then I do get a "Webpage not found" message.
My question is this: Is there anything that I am not doing but should? As I said, I am new to this, and after some hunting around on the internet, I have a suspicion that there is some server (HTTP, Express, Express 3/4?) that I am not establishing. However, it is of note that the code worked as is in ver0.9.16 (using the .socket() and .listen() functions which were removed from my code for migration to ver1.0). If there is any information that is missing, I will do my best to provide it as soon as possible.
-
I am using:
Macintosh OS 10.6.8
Google Chrome version 36.0.1985.125
socket.io ver1.0
node.js v0.10.29
The address in the error is wrong (assuming you haven't set up a local name resolver).
The address in the error begins with:
file
When it should begin with something like:
localhost:4000
The issue is probably in some of the js-config files for the web application (not the server). Or maybe you're trying to access the file locally (eg. just open the html-file in the browser) instead of typing the address localhost:4000.
I had the same problem that running file in the browser:
eg.
"file:///C:/apppath/index.html"
Try running from the server
eg.
"http://your.app:4000/index.html"
I had the same issue - I wasn't able to connect to my socket.io server through my client on the same machine on mac. I disabled the firewall and it resolved the issue. I guess we could use xhr-polling instead and overcome this.
Vikram
I ran into a similar problem, but the solution to my problem had nothing to do with CORS. In my case, which is a Cordova 4.0.0 app using socket.io, I was using an incorrect URL for the socket server. I was using a socket server URL like this:
//socketserver.example.com:8000
This worked fine in the desktop Chrome browser, but in the Cordova webview on the phone or emulator there were many errors regarding failed GET and POST requests to a URL that started with
http://file/socket.io
The correct URL in my case turned out to be:
http://socketserver.example.com:8000
Note the complete scheme at the beginning of the URL.
Related
I have a golang API app that is currently serving double-duty as a Single Page App server with static content using the method shown here: https://hackandsla.sh/posts/2021-11-06-serve-spa-from-go/
Everything is working great in terms of navigation until users try to refresh URIs with encoded JSON in them. For example:
/licenses
will refresh file and draw the page as it would normally have appeared through internal history.push()
/licenses/show/%7B"options":%7B"container":"home","field":"date","order":"desc"%7D,"license":"00001a"%7D
will cause the 500 error.
I did the initial development with IIS as a web server so these Refresh errors never happened in that environment. And when the server is ready to be deployed I plan to use Caddy and reverse proxy the API and am assuming it will handle the Refreshes with the same aplomb as IIS.
But for now I am hoping to run tests against my simple server so I'd like to solve this issue out of curiosity in addition to development expediency.
Bottom line: What cause golang http.ListenAndServe to return 500 errors?
UPDATE:
As I need to be able to test and hand off for others I have converted to a querystring which http.ListenAndServe is happy with:
/licenses/show/%7B"options":%7B"container":"home","field":"date","order":"desc"%7D,"license":"00001a"%7D
causes 500 error
/licenses/show?state=%7B"options":%7B"container":"home","field":"date","order":"desc"%7D,"license":"00001a"%7D
works fine
I have developed a Laravel API for my SPA. Sometimes I'm using query parameters to provide data to the API. But if there's an # sign inside the API URL the server responds with a 500 - Internal Server Error. Example...
Here I will get the error:
http://www.mywebsite.com/api/user/login?name=example.user#gmail.de&password=changeMe
Here everything works fine:
http://www.mywebsite.com/api/user/login?name=exampleUser&password=changeMe
Locally both ways are working. But when tested on the live server the error occurred.
Does anyone know what the problem is? I'm using an Apache Server with Plesk, if it helps. ;-)
Ok, I've solved the problem. If someone else has the same error:
Just set the server-sides default charset to utf-8 fixed that problem!
The web app that I am building in meteor works in chrome and I.E.(Other than a UI bug in I.E.) but it starts acting strange in Firefox. When I run it on my localhost and on the deployment to meteor.com, I don't get any errors in the console in the browsers' developer tools.
When I run it in Firefox, things start acting weird. On Mac OSX, if I run the app on my localhost and open it in FF it is just fine. However, when I open up the app that deployed to meteor.com via meteor deploy [my-app-url].com, I get the following errors but I can still use everything in my app:
Error 1:
mutating the [[Prototype]] of an object will cause your code to run very slowly;
instead create the object with the correct initial [[Prototype]] value using Object.create
Error 2:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
at https://ddp--3071-[my-app-url].com/sockjs/info?cb=v9pygo9mzn.
(Reason: CORS request failed).
While right now I am not able to figure out what is causing the first error, I am mostly worried about the second error.
When I open up the app from it's deployment in FF on Windows 8, I get the first error once, and then I get the second error repeatedly and the app never loads(it just stays on my loading template from the iron router). My deployed app runs just fine on Chrome and I.E.
I don't send any kind of request to another server in my app, so I am not sure why I am getting a CORS request error. I have not set up SSL or began to make a certificate yet, so I am not sure if this could be causing this kind of error in FF as I got another exception on my login page in FF on my localhost saying that I shouldn't have password elements when I'm not using https.
Does anyone know what could be causing this?
Sorry that I provide any code, as I don't know what code I would post to solve this problem since I don't actually request anything from another server in code that I have written.
Thanks in advance for any responses!
If anyone is interested, it seems as if my combination of the aldeed:collectio2 package and one of my other packages was the cause of my problems. I removed this package and my issues went away.
Ok so since I applied an SSL Cert to our site the graphs in the dashboard have stopped working. i read this site
EDIT: forgot to add, im trying to get this working in the magento dashboard.
http://www.phpro.be/blog/detail/magento-dashboard-charts-not-working
which states to add "true" to the GetChartUrl() function within
app/design/adminhtml/default/default/template/dashboard/graph.phtml
this works on a site not using SSL.
I then found this site
http://webguru.org/2009/11/09/php/how-to-use-google-charts-api-in-your-secure-https-webpage/comment-page-1/#comment-988
but this supposedly opens up opportunity for SQL injection and other malicious attacks.
next I found this site
http://store.ivvy.ru/blog/chartssl/
and followed the instructions but still the charts aren't working.
i tried changing
const API_URL='http://chart.apis.google.com/chart';
to both
const API_URL='//chart.apis.google.com/chart';
const API_URL='https://chart.apis.google.com/chart';
but neither worked.
Can anyone point me to any other examples / explanations, or explain how to get this working?
Many Thanks
Do you use Firebug or another browser debug tool? If so, what is the error on the Console tab when you load the page containing the charts. I can tell you now, it's most likely due to trying to load a HTTP JS script over an HTTPS connection...which will fail.
Try using their latest API URL which supports HTTPS:
https://chart.googleapis.com/chart
We have a websocket server on port 8080 setup on a Linode box. Chrome and Opera work just fine. Firefox however complains that the operation is insecure.
"The operation is insecure: Code 18"
If I try to create a new WebSocket object in the web console before the page is loaded everything is fine. However, after the page loads something is screwy then I cannot create the object anymore. See the attached screenshot.
I have no idea what operation is insecure or even how to go about diagnosing this.
As you point out in another answer, https:// to ws:// is disallowed by default on firefox.
Going to firefox's about:config and toggling network.websocket.allowInsecureFromHTTPS will get rid of the SecurityError.
I fixed this. The app itself is under SSL but the websocket being accessed is not. Chrome and Opera don't care but Firefox does. According to:
https://bugzilla.mozilla.org/show_bug.cgi?id=303952
This is known and is not considered a bug. Mozilla's response: wontfix
Solution, put websocket server under SSL and use wss://
This is a hunch based off limited info, and I probably should put this into a comment, but I don't have enough reputation points to do that yet.
Looking at your log, it seems as if 24 seconds are passing from the receipt of [object Websocket] (time 17:46:36.683) until you get The connection to ws://.....(time 17:47:00:952) error message.The long delay leads me to believe that the server could be timing out and closing the websocket connection. Look at this answer for a potential solution.
Had the same problem and attempted to fix by changing network.websocket.allowInsecureFromHTTPS in about:config which did not work.
Ended up finding this post => Unhandled Rejection (SecurityError): The operation is insecure. On a fresh create-react-app project
Changing this in index.js ended up working for me
serviceWorker.register();
//serviceWorker.unregister();
Open "about:config" url in firefox. Search for allowInsecureFromHTTPS and set it to true
Beside secure ssl context and cross-origin policies, assigning some port can trigger the error as well.
What are valid http ports for Firefox? I don't know precisely, but have to be between 1500 and 64000, or the console will display:
SecurityError: The operation is insecure.
And http links will say:
This address is restricted
This address uses a network port which is normally used for purposes other than Web browsing.
Firefox has canceled the request for your protection.