-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (54 loc) · 2.07 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
var express = require("express");
var path = require("path");
var bodyParser = require("body-Parser");
const chalk = require("chalk");
var app = express();
var request = require("request");
var data_service = require("./data_service.js");
var exphbs = require("express-handlebars");
//component for the localhost
var HTTP_PORT = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended:true}));
app.use(express.static('public'));
app.use(express.static('node_modules'));
function onHttpStart(){
console.log("Express http server sets and listening on "+HTTP_PORT);
}
app.set("view engine", ".hbs");
app.engine(".hbs", exphbs({
extname: ".hbs",
helpers: {
equal:(lvalue,rvalue,option) =>{
if(arguments.length <= 3) throw new Error ("Express Handlebars accepts less than three paras");
if(lvalue != rvalue){return HTMLOptionsCollection.inverse(this);}
else {return HTMLOptionsCollection.fn(this)};
}
}
}));
app.listen(HTTP_PORT,function onHttpStart(){
console.log(chalk.green("------Nodverve is statrt to fly-------"));
console.log(chalk.green("----------------SeatBelt---------------"));
return new Promise((res,req)=>{
//call the data_service init
data_service.initialize().then(() =>{
console.log(chalk.blue("------Data_service is on-------"));
}).catch((err) =>{
console.log(chalk.red("!!!!!!!" + err));
});
});
});
app.get("/zv/users/:user_id",(req,res)=>{
data_service.UserId(req.query.status).then((data)=>{
res.render("User", {data:data,title:"User"});
}).catch((err)=>{
res.render("User",{data:data, title : "User"});
});
});
app.get("/zv/users/:user_id/tasks/:task_id",(req,res)=>{
data_service.UserTask(req.query.status).then((data)=>{
res.render("Task for User" + user_id, {data:data,title:"Task"});
}).catch((err)=>{
res.render("Task for User" + user_id,{data:data, title : "Task"});
});
});