Permalink
Browse files

Fixing bugs

  • Loading branch information...
1 parent 582a256 commit eac475b1abcf2f51ed85ca718fd48e2e16d8d0da xFontroSF committed Sep 26, 2012
Showing with 43 additions and 27 deletions.
  1. +5 −3 client.js
  2. +38 −24 server.js
View
@@ -1,13 +1,15 @@
var http = require("http");
var req_options = {
- host: '192.168.7.13',
+ //host: '192.168.7.13',
+ //port: '8080',
+ host: '127.0.0.1',
port: '8080',
method: 'POST',
//path: '/sumar?op1=2&op2=4', //Exemple per a GET.
- path: 'http://aritmeticops-nodetestingsf.rhcloud.com/sumar', //Exemple per a POST.
+ path: '/sumar',//path: 'http://aritmeticops-nodetestingsf.rhcloud.com/sumar', //Exemple per a POST.
headers: {
- Host: "aritmeticops-nodetestingsf.rhcloud.com"
+ //Host: "aritmeticops-nodetestingsf.rhcloud.com"
}
};
View
@@ -10,8 +10,6 @@ var ipaddr = process.env.OPENSHIFT_INTERNAL_IP || "127.0.0.1",
function start(route, handle) {
function onRequest(request, response) {
var data = '',
- op1 = 0,
- op2 = 0,
pathname = url.parse(request.url).pathname;
if(request.method === 'POST'){
@@ -23,35 +21,51 @@ function start(route, handle) {
function(){
var dataObj = JSON.parse(data);
- console.log("Segons el servidor: Vull sumar "+op1+" i "+op2);
- op1 = parseInt(dataObj.op1);
- op2 = parseInt(dataObj.op2);
+ var op1 = parseInt(dataObj.op1);
+ var op2 = parseInt(dataObj.op2);
console.log("Request for " + pathname + " received. With operands "+op1+" and "+op2);
+
+ route(
+ handle,
+ pathname,
+ op1,
+ op2,
+ function(resultat){
+ response.writeHead(200, {});
+ response.write(JSON.stringify(resultat));
+ response.end();
+ },
+ function(err){
+ response.writeHead(err.errorCode, err.errorContent);
+ response.write(JSON.stringify(err.errorDescription));
+ response.end();
+ });
});
} else if(request.method === 'GET'){
var parsedUrl = url.parse(request.url);
- op1 = parseInt(qs.parse(parsedUrl.query).op1);
- op2 = parseInt(qs.parse(parsedUrl.query).op2);
- console.log("Request for " + parsedUrl.pathname + " received.");
+ var op1 = parseInt(qs.parse(parsedUrl.query).op1);
+ var op2 = parseInt(qs.parse(parsedUrl.query).op2);
+ console.log("Request for " + parsedUrl.pathname + " received.");
+
+ route(
+ handle,
+ pathname,
+ op1,
+ op2,
+ function(resultat){
+ response.writeHead(200, {});
+ response.write(JSON.stringify(resultat));
+ response.end();
+ },
+ function(err){
+ response.writeHead(err.errorCode, err.errorContent);
+ response.write(JSON.stringify(err.errorDescription));
+ response.end();
+ });
}
-
- route(
- handle,
- pathname,
- op1,
- op2,
- function(resultat){
- response.writeHead(200, {});
- response.write(JSON.stringify(resultat));
- response.end();
- },
- function(err){
- response.writeHead(err.errorCode, err.errorContent);
- response.write(JSON.stringify(err.errorDescription));
- response.end();
- });
+
/*request.on('error', function(e){
console.log("Request Caught the error: "+e);

0 comments on commit eac475b

Please sign in to comment.