私はこのコード
var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken');
function isNullOrWhitespace(input) {
if (typeof input === 'undefined' || input == null) return true;
return input.replace(/\s/g, '').length < 1;
}
function hasWhiteSpace(s) {
return /\s/g.test(s);
}
router.use(function(req, res, next) {
var auth_key = req.headers['auth_key'];
var api_key = req.query['api_key'];
var source_id = req.query['source_id'];
if((auth_key) && (api_key) && (source_id) && (auth_key!==undefined) && (api_key!==undefined) &&(source_id!==undefined) && !isNullOrWhitespace(auth_key) && !isNullOrWhitespace(api_key) && !isNullOrWhitespace(source_id) && !hasWhiteSpace(auth_key) && !hasWhiteSpace(api_key) && !(hasWhiteSpace(source_id)))
{
next();
}
else
{
if((!auth_key) || (auth_key===undefined) || isNullOrWhitespace(auth_key) || hasWhiteSpace(auth_key))
{
var auth_key_error = {
status : "fail",
message : "Invalid Auth Key"
};
return res.status(403).send(auth_key_error);
}
else if((!api_key) || (api_key===undefined) || isNullOrWhitespace(api_key) || hasWhiteSpace(api_key))
{
var api_key_error = {
status : "fail",
message : "Invalid API Key"
};
return res.status(403).send(api_key_error);
}
else if((!source_id) || (source_id===undefined) || isNullOrWhitespace(source_id) || hasWhiteSpace(source_id))
{
var sourceid_error = {
status : "fail",
message : "Invalid Source ID"
};
return res.status(403).send(sourceid_error);
}
else{
var fieldsempty_error = {
status : "fail",
message : "Some field was incorrect or left empty"
};
return res.status(403).send(fieldsempty_error);
}
}
});
router.get('/', function (req, res, next) {
var auth_key = req.headers['auth_key'];
var api_key = req.query['api_key'];
var source_id = req.query['source_id'];
//do something here
});
module.exports = router;
を持っている今、私は適切にgetメソッドでこれらの変数にアクセスする方法をgetメソッド
で再び変数は[]ヘッダ[]とクエリ文字列を使用したいですか?
また、サニタイズとは何ですか?
このコードで変数のサニタイズを実行する必要がありますか?
またもう一つ..私たちは唯一のミドルウェアのために1つの利用機能を持っている場合、我々は何をすべき次のメソッドは次の順序ミドルウェアの機能を実行するために使用されていることを
を読みますか?