I am developing on a Ubuntu server that I do not own. This is my first node application.
Node.js has been installed on the server. I have created a simple server file:
Server.js
var http = require("http");
http.createServer(function (request, response){
response.writeHead(200, {'Content-Type': 'text/plain'});
//response to send out
response.end('Hello sof');
//print to screen
console.log('request processed\n');
}).listen(1234);
console.log("Server Running on 1234");
In putty I run the server with this command:
node Server.js
In another instance of putty I run this command:
curl http://my.url.website.ca:1234/*curl request*/
In the putty instance where I ran the curl command I get this output:
Hello sof
In the putty instance where I ran the node Server this get printed to the screen:
request processed
So it looks like the server is running. However when I put http://my.url.website.ca:1234 into my browser I get this error:
GET http://my.url.website.ca:1234/ net::ERR_CONNECTION_TIMED_OUT
and nothing is printed to the screen in putty window where the server is running. Am I doing something wrong or missing something in my code? Or is this a configuration issue?
I linked the server person to this page and he confirmed that the issue was in fact the firewall. The port I was trying to use was not open. The port was then opened and I was able to connect through the browser.
I then tested it with my jquery application and had a CORS error. For anyone else running into the same issue as me you will probably have that issue next. I fixed it by adding these headers:
response.setHeader('Access-Control-Allow-Origin', 'http://my.website.ca');
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
response.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With