On May 17, 2013, at 07:31, Dandi wrote:

> I'm going to develop this service: I use CakePHP Framework to develop a web 
> application (consider this address for it: http://news.webapp.it) that allow 
> clients to request news from social networks.
[snip]
> So, I think that a solution for my problem is to adopt a NodeJS server (that 
> I can test at this url http://news.webapp.it/nodejs - because I made a folder 
> in CakePHP root, named Nodejs, and customize .htaccess file for this) to make 
> those several request for parsing pages, leaving free the direct channel with 
> the server for other possible requests from client.

If this is what you want -- for CakePHP to deal with most of the site, and for 
nodejs to be used for just one part of the URL space on that same host and port 
-- then you'll have to configure your web server (Apache? Nginx?) to *proxy* 
requests for those URLs to nodejs. You don't need any "nodejs" folder in 
CakePHP because CakePHP has nothing to do with what the web server does to 
proxy those requests.

The only reason to go to all that trouble is if you need to publish any 
nodejs-specific URLs and you want the URLs to remain pretty and look like 
they're all part of a single service. But if you only need to access nodejs 
through AJAX then it doesn't matter what the URLs look like.

A simpler configuration would be to leave CakePHP handling all of your URLs on 
your main hostname and port, and start the nodejs server on a separate port 
and/or IP address and talk to it that way. The rest of the code you show below 
is already doing this.


> $(document).ready(function() {
> 
>       $('.first').click( function(){  
>           $.getJSON("http://192.aaa.bbb.ccc:8077/&callback=?";,

Here, for example, you show that you're wanting to directly access the nodejs 
server at its port 8077 (while CakePHP remains on port 80 presumably through 
Apache or Nginx or similar web server).

Also, there appears to be a typo in the URL. You probably meant 
"?callback=something".

>                       function(data){
>                               console.log('Done with success!');
>                       },
>                       function(jqXHR, textStatus, errorThrown) {
>                       console.log('error ' + textStatus + " " + errorThrown);
>               });
>       });
>       
> });
> 
> </script>
> 
> 
> NodeJS Server-Side: server.js
> 
> var http = require('http');
> var querystring = require('querystring');
> var url = require('url');
> var sys = require('sys');
> 
> http.createServer(function (req, res) {
>     var pquery = querystring.parse(url.parse(req.url).query);   
>     sys.puts("PQUERY: "+pquery);
> 
>     var callback = (pquery.callback ? pquery.callback : '');
>     sys.puts("Callback: "+ callback);
>     var returnObject = {message: "Hello World!"};
>     
>     var returnObjectString = JSON.stringify(returnObject);
> 
>     res.writeHead(200, {'Content-Type': 'text/plain'});
>     res.end(callback + '(\'' + returnObjectString + '\')');
> }).listen(8077, '192.aaa.bbb.ccc');

It looks to me like this should work: it should create an http server on port 
8077 responding to the hostname 192.aaa.bbb.ccc and delivering the "Hello 
World!" response to any requested URL. It may be simpler if you omit the 
hostname; then it'll respond to any hostname on that port number.


> This javascript client side code doesn't work but the server starts correctly 
> and if I try http://news.webapp.it/nodejs in the browser address field, it 
> return the message "Hello World".

That should not be. That suggests that the nodejs server is in fact running on 
port 80. Unless you've already configured some sort of proxy from your primary 
web server, but your message made no mention of that.



-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to