-
Notifications
You must be signed in to change notification settings - Fork 0
/
infos.txt
28 lines (27 loc) · 1.19 KB
/
infos.txt
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
EXEMPLO DE COMO FAZER UMA ROTA PARA O SERVIDOR
this.application.get('/info', [(req, resp, next) => {
if (req.userAgent() && req.userAgent().includes('MSIE 7.0')) {
// resp.status(400);
// resp.json({message: 'atualize seu navegador'});
// return next(false);
let error: any = new Error();
error.statusCode = 400;
error.message = 'atualize seu navegador';
return next(error);
}
return next();
},
(req, resp, next) => {
// resp.contentType = 'application/json'; set response para json
// resp.setHeader('Content-Type','application/json'); modo mais tradicional de se setar o header
// resp.send({message: 'hello'}); enviar a response, consegue identificar o tipo da responsta automaticamente
// resp.status(400); set o status da response nesse caso para erro
resp.json({
browser: req.userAgent(), // pega as infos do browser da requisicao
method: req.method, // metodo usado na requisicao
url: req.href(), // equivalente a path, rota usada na requisicao
path: req.path(), // equivalente a href
query: req.query, // pega parametros utilizados na rota da requisicao
});
return next();
}]);