-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
72 lines (72 loc) · 2.7 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"use strict";
exports.__esModule = true;
var express = require("express");
var logger = require("morgan");
var url = require("url");
var bodyParser = require("body-parser");
// Creates and configures an ExpressJS web server.
var App = /** @class */ (function () {
//Run configuration methods on the Express instance.
function App() {
this.express = express();
this.middleware();
this.routes();
}
// Configure Express middleware.
App.prototype.middleware = function () {
this.express.use(logger('dev'));
this.express.use(bodyParser.json());
this.express.use(bodyParser.urlencoded({ extended: false }));
};
// Configure API endpoints.
App.prototype.routes = function () {
/* This is just to get up and running, and to make sure what we've got is
* working so far. This function will change when we start to add more
* API endpoints */
var router = express.Router();
router.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
router.get('/one', function (req, res, next) {
res.send('request one');
});
router.get('/add', function (req, res, next) {
var urlParts = url.parse(req.url, true);
var query = urlParts.query;
console.log('var1:' + query.var1);
console.log('var2:' + query.var2);
var value1 = parseInt(query.var1);
var value2 = parseInt(query.var2);
var sum = value1 + value2;
//var sum = query.var1 + query.var2;
var msg = 'addition of ' + query.var1 + ' plus ' + query.var2 + ' equals ' + sum;
console.log(msg);
res.send(msg);
});
var fname2;
router.get('/name/:fname', function (req, res, next) {
var name;
console.log(':fname = ' + req.params.fname);
if (req.params.fname === 'israelh') {
name = fname2 + ' hilerio';
}
else {
name = fname2 + ' world';
}
console.log("Your name is: " + name);
res.send("Your name is: " + name);
});
router.param('fname', function (req, res, next, value) {
console.log('The param value is: ' + value);
fname2 = value + "-ABCD";
console.log('fname2:' + fname2);
next();
});
this.express.use('/', router);
this.express.use('/json', express.static(__dirname + '/json'));
};
return App;
}());
exports.App = App;