-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (47 loc) · 1.78 KB
/
Copy pathapp.js
File metadata and controls
55 lines (47 loc) · 1.78 KB
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
var express = require("express");
var app = express();
var request = require('request');
var mysql = require("mysql");
var pool = mysql.createPool({
host: "localhost",
port: 3306,
user: "sindhu",
password: "disha",
database: "todo_list",
connectionLimit: 4
});
app.get("/api/list/categories", function (req, res) {
request('http://www.chabu.in/api/v2/sync_app_data', function (error, response, body) {
if (!error && response.statusCode == 200) {
res.status(200).json(body);
//console.log(body); // Show the HTML for the Google homepage.
}else{
console.log("Error Occurred", error);
res.status(500).end();
}
});
});
app.get("/api/list/business/:catId", function (req, res) {
request('http://www.chabu.in/api/v2/sync_app_data', function (error, response, body) {
if (!error && response.statusCode == 200) {
var catId = req.params.catId;
console.log(typeof(body));
var result = JSON.parse(body);
var busi = result.data;
var business = busi.business;
var xmlhttp = eval(busi);
var filteredResult = xmlhttp.filter(function(el) { return el.category_id == catId});
res.status(200).json(filteredResult);
//console.log(body); // Show the HTML for the Google homepage.
}else{
console.log("Error Occurred", error);
res.status(500).end();
}
});
});
app.use(express.static(__dirname + "/public"));
app.use("/bower_components", express.static(__dirname + "/bower_components"));
app.set("port", process.argv[2] || process.env.APP_PORT || 8080);
app.listen(app.get("port"), function(){
console.info("Application started on port %d", app.get("port"));
});