Skip to content
This repository
Browse code

Works with CloudFoundry. Removed cluster and commander

  • Loading branch information...
commit 7da81c0b4d1f9ecf99c916c6db778b7f60cedbb2 1 parent 2481151
xfontroSF authored October 11, 2012

Showing 1 changed file with 65 additions and 86 deletions. Show diff stats Hide diff stats

  1. 151  app.js
151  app.js
... ...
@@ -1,104 +1,83 @@
1 1
 // Express sample aritmetic application.
2 2
 var	express = require("express"),
3  
-	operacionsAritmetiques = require("./operacionsAritmetiques"),
4  
-	args = require("commander"),
5  
-	cluster = require("cluster");
  3
+	operacionsAritmetiques = require("./operacionsAritmetiques");
6 4
 
7 5
 var port = process.env.OPENSHIFT_INTERNAL_PORT || process.env.VMC_APP_PORT || "8080",
8 6
 	app = express(),
9 7
 	handle = {};
10  
- 
11  
-args
12  
-	.version('0.1')
13  
-	//.option('-p, --port [number]', 'client port', 8080)
14  
-	.option('-f, --folder [folderpath]', 'root folder path', './' )
15  
-	.option('-c, --cluster', 'cluster of processes')
16  
-	.parse(process.argv);
17 8
 
  9
+app.configure(function (){
  10
+	app.use(express.bodyParser());
  11
+});
18 12
 
19  
-	//console.log('Binding to port ', args.port);
20  
-	console.log('Folder path: ', args.folder);
21  
-	console.log('Processor: ' + require('os').cpus()[0].model);
22  
-
23  
-if(args.cluster && cluster.isMaster) {
24  
-	console.log('Cluster: ' + args.cluster);
25  
-	require('os').cpus().forEach(function (item) {
26  
-		cluster.fork();
27  
-	});
28  
-} else {
29  
-	app.configure(function (){
30  
-		app.use(express.bodyParser());
31  
-	});
32  
-	
33  
-	// Handlers for POST.
34  
-	app.post("/sumar", function(request, response){operacionsAritmetiques.sumar(request.body.op1, request.body.op2, function(error, resultat){
35  
-						if(error){
36  
-							response.json(error.errorCode, { error: error.errorDescription });
37  
-						}else {
38  
-							response.json(200, {resultat: resultat});
39  
-						}
40  
-	});});
41  
-
42  
-	app.post("/restar", function(request, response){operacionsAritmetiques.restar(request.body.op1, request.body.op2, function(error, resultat){
43  
-						if(error){
44  
-							response.json(error.errorCode, { error: error.errorDescription });
45  
-						}else {
46  
-							response.json(200, {resultat: resultat});
47  
-						}
48  
-	});});
  13
+// Handlers for POST.
  14
+app.post("/sumar", function(request, response){operacionsAritmetiques.sumar(request.body.op1, request.body.op2, function(error, resultat){
  15
+					if(error){
  16
+						response.json(error.errorCode, { error: error.errorDescription });
  17
+					}else {
  18
+						response.json(200, {resultat: resultat});
  19
+					}
  20
+});});
49 21
 
50  
-	app.post("/multiplicar", function(request, response){operacionsAritmetiques.multiplicar(request.body.op1, request.body.op2, function(error, resultat){
51  
-						if(error){
52  
-							response.json(error.errorCode, { error: error.errorDescription });
53  
-						}else {
54  
-							response.json(200, {resultat: resultat});
55  
-						}
56  
-	});});
  22
+app.post("/restar", function(request, response){operacionsAritmetiques.restar(request.body.op1, request.body.op2, function(error, resultat){
  23
+					if(error){
  24
+						response.json(error.errorCode, { error: error.errorDescription });
  25
+					}else {
  26
+						response.json(200, {resultat: resultat});
  27
+					}
  28
+});});
57 29
 
58  
-	app.post("/dividir", function(request, response){operacionsAritmetiques.dividir(request.body.op1, request.body.op2, function(error, resultat){
59  
-						if(error){
60  
-							response.json(error.errorCode, { error: error.errorDescription });
61  
-						}else {
62  
-							response.json(200, {resultat: resultat});
63  
-						}
64  
-	});});
  30
+app.post("/multiplicar", function(request, response){operacionsAritmetiques.multiplicar(request.body.op1, request.body.op2, function(error, resultat){
  31
+					if(error){
  32
+						response.json(error.errorCode, { error: error.errorDescription });
  33
+					}else {
  34
+						response.json(200, {resultat: resultat});
  35
+					}
  36
+});});
65 37
 
66  
-	// Handlers for GET
67  
-	app.get("/:operation", function (request, response, next){
68  
-		var op;
69  
-		
70  
-		if(request.params.operation == "sumar"){
71  
-			op = operacionsAritmetiques.sumar;
72  
-		}else if(request.params.operation == "restar"){
73  
-			op = operacionsAritmetiques.restar;
74  
-		}else if(request.params.operation == "multiplicar"){
75  
-			op = operacionsAritmetiques.multiplicar;
76  
-		}else if(request.params.operation == "dividir"){
77  
-			op = operacionsAritmetiques.dividir;
78  
-		}else{
79  
-			op = undefined;
80  
-		}
81  
-		
82  
-		if(typeof op === 'function'){
83  
-			op( parseInt(request.param('op1')),
84  
-				parseInt(request.param('op2')),
85  
-				function(error, resultat){
  38
+app.post("/dividir", function(request, response){operacionsAritmetiques.dividir(request.body.op1, request.body.op2, function(error, resultat){
86 39
 					if(error){
87 40
 						response.json(error.errorCode, { error: error.errorDescription });
88 41
 					}else {
89 42
 						response.json(200, {resultat: resultat});
90 43
 					}
91  
-			});
92  
-		}else {
93  
-			next();
94  
-		}
95  
-	});
  44
+});});
  45
+
  46
+// Handlers for GET
  47
+app.get("/:operation", function (request, response, next){
  48
+	var op;
  49
+	
  50
+	if(request.params.operation == "sumar"){
  51
+		op = operacionsAritmetiques.sumar;
  52
+	}else if(request.params.operation == "restar"){
  53
+		op = operacionsAritmetiques.restar;
  54
+	}else if(request.params.operation == "multiplicar"){
  55
+		op = operacionsAritmetiques.multiplicar;
  56
+	}else if(request.params.operation == "dividir"){
  57
+		op = operacionsAritmetiques.dividir;
  58
+	}else{
  59
+		op = undefined;
  60
+	}
  61
+	
  62
+	if(typeof op === 'function'){
  63
+		op( parseInt(request.param('op1')),
  64
+			parseInt(request.param('op2')),
  65
+			function(error, resultat){
  66
+				if(error){
  67
+					response.json(error.errorCode, { error: error.errorDescription });
  68
+				}else {
  69
+					response.json(200, {resultat: resultat});
  70
+				}
  71
+		});
  72
+	}else {
  73
+		next();
  74
+	}
  75
+});
96 76
 
97  
-	// Default handler
98  
-	app.all("/*", function (request, response){
99  
-		response.json(404, {error:'404 Not Found'});
100  
-	});
  77
+// Default handler
  78
+app.all("/*", function (request, response){
  79
+	response.json(404, {error:'404 Not Found'});
  80
+});
101 81
 
102  
-	app.listen(port);
103  
-	console.log("Server has started at port: "+port);
104  
-}
  82
+app.listen(port);
  83
+console.log("Server has started at port: "+port);

0 notes on commit 7da81c0

Please sign in to comment.
Something went wrong with that request. Please try again.