how to send my first HTTP request

27 views
Skip to first unread message

Saul Aguado

unread,
Dec 23, 2013, 5:50:36 PM12/23/13
to clou...@googlegroups.com
Hi,

i just created my app and it seems it's running fine:

23 Dec 22:49:35 - Inside Node Virtual Machine
23 Dec 22:49:35 - Version: v0.8.26
23 Dec 22:49:35 - Owning user: 501
23 Dec 22:49:35 - User Changed: 501
23 Dec 22:49:35 - Checking for /etc
23 Dec 22:49:35 - Update /etc/resolve.conf with Googles DNS servers..
23 Dec 22:49:35 - Checking for /tmp
23 Dec 22:49:35 - Checking for /mnt
23 Dec 22:49:35 - Setting up sandbox..
23 Dec 22:49:35 - Munging require paths..
23 Dec 22:49:35 - Globalizing Buffer
23 Dec 22:49:35 - Reading startup file server.js...
23 Dec 22:49:35 - Final user check: 501
23 Dec 22:49:35 - Cloudnode wrapped script starting (16194) at Mon Dec 23 2013 22:49:35 GMT+0100 (UTC)
Servidor Iniciado
last line is a console.log("Servidor Iniciado")

my question is: how do i send requests to the server? (my server listens on the port 8888)

i tried: 


but i get nothing.. am i missing anything ?

Hans J. Schroeder

unread,
Dec 24, 2013, 3:50:12 AM12/24/13
to clou...@googlegroups.com
Just use the URL without a port. All apps are accessible on the standard port 80 from outside. 


--
You received this message because you are subscribed to the Google Groups "Cloudnode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloudnode+...@googlegroups.com.
To post to this group, send email to clou...@googlegroups.com.
Visit this group at http://groups.google.com/group/cloudnode.
For more options, visit https://groups.google.com/groups/opt_out.

Saul Aguado

unread,
Dec 24, 2013, 4:26:45 AM12/24/13
to clou...@googlegroups.com
i just tried and nothing happens..

i am quite lost at that point:

my VM is listening all the ports ? how does it know wich port to use?

My server.js (the boot file) and server2.js (where the server is, called by server.js):

server.js:

//server.js
var server = require("./server2");
var router = require("./router");
var requestHandlers = require("./requestHandlers");

//handlers for incoming requests
var handle = {}
handle["/"] = requestHandlers.iniciar;

handle["/addFriend"] = requestHandlers.addFriend;
handle["/removeFriend"] = requestHandlers.removeFriend;

//start the server
server.iniciar(router.route, handle);

server2.js:
 
//server2.js
var http = require("http");
var url = require("url");

function iniciar(route, handle) {

  function onRequest(request, response) {
        var dataPosteada = "";
        var pathname = url.parse(request.url).pathname;

        request.setEncoding("utf8");

        request.addListener("data", function(trozoPosteado) {
          dataPosteada += trozoPosteado;
    });

    request.addListener("end", function() {
      route(request, handle, pathname, response, dataPosteada);
    });

  }

  http.createServer(onRequest).listen(8888);
  console.log("Servidor Iniciado");
}

exports.iniciar = iniciar;

Saul Aguado

unread,
Dec 24, 2013, 4:34:38 AM12/24/13
to clou...@googlegroups.com
ok.. i found it:

Internal Port
9557

i don't know how to change it so i am now listening on the 9557 and everything works fine..

thnx!!!

El lunes, 23 de diciembre de 2013 23:50:36 UTC+1, Saul Aguado escribió:

Hans Schroeder

unread,
Dec 24, 2013, 6:12:36 AM12/24/13
to clou...@googlegroups.com
Great.

Just to clarify. Your code must listen on the port that is reserved by the platform for your app, in your case 9557. 
There is an environment variable (app_port) for that. Normally you write something like:

.listen(process.env.app_port || 8080);

Then your app listens to port 8080 when running locally, but when deployed to the platform, it uses the environment variable that is automatically set 
to the correct port for your app. Web requests to your app happen always on the standard port 80. The routing grid proxies all requests the corresponding application
port (9557 in your case). The same goes for websocket connections.

- Hans 
Reply all
Reply to author
Forward
0 new messages