мой код server.js:JSON для запроса
var express = require('express');
var app = express();
// set the view engine to ejs
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/dist'));
if (par.query.login) {
var data={
"user": {
"displayName": "fares alkhawaja",
"username": "elkhawajah"
},
"profile": {
"photo":"null",
"fullName": "fares sameer alkhawaja"
},
"balance": {
"overall": 200,
"outstanding": 149
},
"currentTasks": [{
"isProject": false,
"id": "1234",
"title": "Build NodeJS Application",
"description": "This is a description for building nodejs application",
"prize": "$500",
"project": "topcoder",
"holder": "elkhawajah"
}, {
"id": "134",
"isProject": false,
"title": "Build NodeJS Application",
"description": "This is a description for building nodejs application",
"prize": "$500",
"project": "topcoder",
"holder": "elkhawajah"
}, {
"id": "12",
"isProject": true,
"title": "Build NodeJS Application",
"description": "This is a description for building nodejs application",
"prize": "$500",
"project": "topcoder",
"holder": "elkhawajah"
}],
"pastTasks": [{
"isProject": false,
"id": "1",
"title": "Build NodeJS Application",
"description": "This is a description for building nodejs application",
"prize": "$500",
"project": "topcoder",
"holder": "fares"
}, {
"id": "2",
"isProject": false,
"title": "Build NodeJS Application",
"description": "This is a description for building nodejs application",
"prize": "$500",
"project": "topcoder",
"holder": "fares"
}, {
"id": "3",
"isProject": true,
"title": "Build NodeJS Application",
"description": "This is a description for building nodejs application",
"prize": "$500",
"project": "topcoder",
"holder": "fares"
}],
"timeline": [{
"title": "Fares uploaded a new submission",
"project": "tasqat",
"task": "Build new endpoint",
"date": new Date(),
"handle": "fares"
}, {
"title": "Fares uploaded a new submission",
"project": "tasqat",
"task": "Build new endpoint",
"date": new Date(),
"handle": "fares"
}]
}
}
app.get("/dashboard", function(req, res) {
//send Jsondata to /view/dashboard.ejs
res.render('dashboard', data);
});
app.listen(process.env.PORT);
console.log(process.env.PORT + ' is the magic port');
моя проблема в том, что мне нужно использовать req.query.login ... если req.query.login {возвращать данные} еще {не возвращают ничего }
например .. когда я использую http://localhost:3000/dashboard данные не должны возвращать ничего, но если пользователь в http://localhost:3000/dashboard?login=true должен вернуть данные ... любую помощь?
Нечеткого вопроса. – nicovank
@nicovank мой вопрос: как использовать json-данные в условиях condtion ... if (req.query.login) {var data = some data} else if not req.query.login var data = null .... like if http: // localhost: 3000/fares dont print data, но когда мне нужно использовать http: // localhost: 3000/fares? login = true распечатать данные –
Показать код 'controller' здесь –