简体   繁体   English

SailsJS:在传递到蓝图之前从URL删除参数

[英]SailsJS: delete parameters from URL before passing to blueprint

We are building an application which uses SailsJS for backend and ExtJS for frontend. 我们正在构建一个将SailsJS用于后端并将ExtJS用于前端的应用程序。 ExtJS automaitcally appends these parameters to every AJAX request coming from its grid: _dc=1421519546371&page=1&start=0&limit=25 ExtJS自动将这些参数附加到来自其网格的每个AJAX请求中:_dc = 1421519546371&page = 1&start = 0&limit = 25

I need to remove these parameters on the Sails side before they are passed to the blueprint actions, so that I can take advantage of the blueprint REST API. 我需要在Sails端删除这些参数,然后再将它们传递给蓝图操作,以便可以利用蓝图REST API。 Where would be the best place to remove these parameters? 删除这些参数的最佳位置在哪里? I can think of my NGINX reverse proxy as one option, but I am sure there is a better place within Sails. 我可以将NGINX反向代理视为一种选择,但是我确信Sails中会有更好的位置。

In sails the easiest place would be to remove them with a policy. 在航行中,最简单的方法是通过政策将其删除。

RemoveParams.js RemoveParams.js

module.exports = function(req, res, next) {
    if(req.query._dc) delete req.query._dc
    // ect ....
    next();
};

Alternate method using undocumented req.options. 使用未记录的req.options的替代方法。 I have not used this, but it would seem to work and was recommended in the comments. 我没有使用它,但是它似乎可以工作,并且在评论中建议使用。

module.exports = function(req, res, next) {
    req.options.values.blacklist = ['_dc']
    // or req.options.values.blacklist.push('_dc') ?? 
    next();
};

If you so choose you could also add your own middleware to replace / remove them as well. 如果这样选择,您还可以添加自己的中间件来替换/删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM