Tag: 过滤

请确定如何创buildfilter来捕获请求和响应并进行logging

在我的restify服务器中,我有一个要添加filter的路由。 在Express中工作的方式(这在Express中工作)是response.on将我的处理程序添加为callback。 然后,在响应返回给请求者之前,我的处理程序将被调用。 这不是我在Restify中看到的行为。 我的猜测是我没有正确地注册我的处理程序的事件机器。 restifyServer.get({ path: "/api/v1/readings", version: ["1.0.0"]}, Reading.getReadings); 我添加一个处理程序: function zipkinTracing(request, response, next){ // handle the callback request and record the trace var trace = zipkin.getTraceFromRequest(request, "ids-api", {address: config.externalIP, port: 80}); if (trace){ zipkin.sendAnnotationReceive(trace); zipkin.sendAnnotation(trace, 'request.headers',JSON.stringify(request.headers)); trace.parentSpanId = trace.spanId; zipkin.sendAnnotation(trace, 'http.uri', request.url); var queryObj = urlLib.parse(request.url, true).query; Object.keys(queryObj).forEach( function(key){ zipkin.sendAnnotation(trace, key, queryObj[key]); […]

Mongoose:查找并过滤嵌套的数组

我试图用Find()命令Find()整个文档,并用条件筛选嵌套数组。 这里使用了一个Schema: var ListSH = new Schema({ name: { type: String, unique: true, required: true}, subject : String, recipients : [ Schema({ uid : { type : ObjectId, required : true, ref:'User', unique: true}, status : { type : Number, default : 1 } },{_id: false}) ] }; 目前我做ListModel.findOne({ _id : req.params.id_list, function(err,list){…}; 邮差给我: { […]

用户分段引擎使用MongoDB

我有一个分析系统,以事件的forms跟踪客户及其属性以及他们的行为。 它使用Node.js和MongoDB(使用Mongoose)来实现。 现在我需要实现一个分段function,允许根据特定的条件将存储的用户分组。 例如, purchases > 3 AND country = 'Netherlands' 在前端,这看起来像这样: 这里一个重要的要求是细分市场实时更新,而不是定期更新。 这基本上意味着,每当用户的属性改变或触发新的事件时,我必须再次检查他属于哪个段。 我目前的做法是将这些段的条件存储为MongoDB查询,然后我可以在用户集合上执行,以确定哪些用户属于某个段。 例如,用于过滤所有使用Gmail的用户的细分将如下所示: { _id: '591638bf833f8c843e4fef24', name: 'Gmail Users', condition: {'email': { $regex : '.*gmail.*'}} } 当用户匹配条件时,我会直接在用户的文档中存储他属于“Gmail用户”细分: { username: 'john.doe', email: 'john.doe@gmail.com', segments: ['591638bf833f8c843e4fef24'] } 但是通过这样做,每次用户数据发生变化时,我都必须执行所有段的查询,以便我可以检查他是否是段的一部分。 从性能的angular度来看,这感觉有些复杂和繁琐。 你可以想办法解决这个问题吗? 也许使用规则引擎,并在应用程序中而不是在数据库中进行处理?

Node.js:SyntaxError:意想不到的标记:编译ejs时

我正在尝试使用Node.JS应用filter到EJS,我得到下面的错误。 我希望消息内容以大写显示。 D:\Apps\Templating\ejs>node server.js D:\Apps\node_modules\ejs\lib\ejs.js:470 throw e; ^ SyntaxError: Unexpected token : while compiling ejs at Function (native) at Object.Template.compile (D:\Apps\node_m odules\ejs\lib\ejs.js:460:12) at Object.compile (D:\Apps\node_modules\ej s\lib\ejs.js:288:16) at handleCache (D:\Apps\node_modules\ejs\l ib\ejs.js:147:16) at Object.exports.render (D:\Apps\node_mod ules\ejs\lib\ejs.js:315:10) at Object.<anonymous> (D:\Apps\Templating\ ejs\server.js:3:17) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) 这是我的代码server.js: var ejs = require('ejs'); […]

nodejs过滤input

在PHP中筛选input数据我使用函数htmlspecialchars和mysql_real_escape_string。 在nodejs中有没有这样的function? 我需要在我的rounter函数中检查所有的input,以防止像xss这样的黑客攻击。 谢谢!

在发送之前过滤响应

我正在编写一个服务器在Node.js和MongoDB与mongoose。 我有一个用户模型,看起来像这样: var User = new Schema({ username : { 'type' : String, 'trim' : true, 'required' : true, 'validate': [usernameValidator, 'whitespace_not_allowed'] }, avatar : { 'type' : String, 'lowercase' : true, 'required' : true }, facebook_id : { 'type' : Number, 'required' : true, 'index' : { unique: true } }, email : { […]

小写与玉模板

我在一个nodejs项目中使用jade 找不到如何定义filter 我有我想显示在select框,小写选项值和大写选项文本的类别 select each cat in categories option(value="lowercase(#{cat})") uppercase(#{cat}) 任何想法 ?