Using node server across domains
- This topic has 6 replies, 2 voices, and was last updated 8 years, 11 months ago by elewis.
-
AuthorPosts
-
February 27, 2014 at 6:08 AM #959elewisParticipant
Hi,
I’m running a website (a wordpress site) on a reception area screen with some buttons beneath that make things happen on the website. The website is on an external server, the buttons are connected to a local machine. I’m using breakout on the website. I’ve tried running the Breakout Server locally and it works great for a few minutes but then seems to go to sleep and stop listening for button presses until I make the breakout server the active window and then it starts working again for another few minutes.
I thought the solution would be to use the node server instead, but I’m getting cross domain CORS errors “XMLHttpRequest cannot load http://localhost:8887/socket.io/?EIO=2&transport=polling. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://XXXXXXX.com’ is therefore not allowed access.”
I’d really appreciate any advice you have!
Thanks,
Emma
February 27, 2014 at 10:50 AM #961soundanalogousMemberHi Emma,
Your project sounds cool. Another person mentioned the issue of Breakout Server not working when the window loses focus. Are you running OS X 10.9?
Regarding the CORS issue. What IP address you’re passing to the IOBoard constructor in your code?
If you’re using the following block of code:
var host = window.location.hostname; // if the file is opened locally, set the host to "localhost" if (window.location.protocol.indexOf("file:") === 0) { host = "localhost"; } var arduino = new IOBoard(host, 8887);
you need to change
host
in the IOBoard constructor to either “localhost” or the specific IP address of the computer the node server is running on. Otherwise by default host points to the content server (the wordpress site).Let me know if that fixes the issue for you. I may also need to add a flag to the node server to disable the ability to serve pages… leaving just the websocket bridge in that case (this is what I was getting at in my tweet… not a lot of room to reply in twitter though so thanks for posting here).
February 27, 2014 at 11:08 AM #962elewisParticipantThank you for your reply! I’ve managed to get it working by editing the io.configure method slightly, but I actually have another problem with the node server in general – even when I run as downloaded with the examples provided. I get an error with line 72 of server.js:
connectedSocket.send(data.toJSON());
TypeError: Object � has no method ‘toJSON’
at SerialPort.<anonymous> (/Applications/Breakout 2/node_server/server.js:72:35)
at SerialPort.EventEmitter.emit (events.js:96:17)
at Object.module.exports.raw [as parser] (/Applications/Breakout 2/node_server/node_modules/serialport/parsers.js:8:13)
at Object.options.dataCallback (/Applications/Breakout 2/node_server/node_modules/serialport/serialport.js:136:15)
at SerialPort._emitData (/Applications/Breakout 2/node_server/node_modules/serialport/serialport.js:305:20)
at afterRead (/Applications/Breakout 2/node_server/node_modules/serialport/serialport.js:283:18)
at /Applications/Breakout 2/node_server/node_modules/serialport/serialport.js:297:9
at Object.wrapper [as oncomplete] (fs.js:362:17)Have you come across this before? Many thanks for your help.
Emma
February 27, 2014 at 11:10 AM #963soundanalogousMemberWhat versions of nodeJS and node-serialport do you have installed?
February 27, 2014 at 11:13 AM #964elewisParticipantNode is v0.8.19 – I tried upgrading to the latest version but then I couldn’t get the node server to run at all.
node-serialport is 1.3.0
February 27, 2014 at 11:53 AM #965soundanalogousMemberYou need Node version v0.10 or higher. I’ll look into this late tonight when I get home and can actually test this. Node and node-serialport keep making non backwards compatible changes so I find that whenever I update either, stuff breaks. It’s quite frustrating.
February 27, 2014 at 12:07 PM #966elewisParticipantThank you so much for helping with this. I tried a few different version combinations and found that node version v0.10.12 and serialport version 1.3.0 works! serialport version 1.3.1 does not.
Many thanks,
Emma
-
AuthorPosts
- The forum ‘Forum’ is closed to new topics and replies.