如何在Nodejs中保护RestFul Api?

现在我正在使用https://github.com/baugarten/node-restful来帮助我在API中工作,问题是? 我正在使用Express框架,有没有办法保护来自其他网站的“GET”请求。 我使用快递的CSRF,但只能通过POST,PUT,DELETE方法使用FOrbidden 403的消息,因为在控制台中使用curl进行交换,但是如果向Get方法进行curl,curl localhost:3000 / postme数组与所有职位。 app.use(express.csrf()); app.use(function(req, res, next){ res.locals.token = req.session._csrf; next(); }); app.use(app.router); 你有什么build议吗? 还有其他模块更好地工作一个Api? 如何保护nodejs中的Api? 什么是最好的实践,一个haver学习? 感谢您的帮助。

NodeClipse – 自动完成 – Mongoose – Javascript库

我试图让自动完成工作在jclipse项目的nodeclipse或eclipse上。 在mongoose对象上进行自动填充(正如我刚刚学习mongoose)。 我想如果我添加js文件作为库,那么它应该能够自动完成…但我不能得到它的工作。 我没有正确设置javascript库(不知道它是在文件夹级还是js级)。 有没有人有任何成功获得自动完成与nodeclipse或eclipse的工作? 我已经看到这个post

将文本文件读入node.js

我刚开始使用node.js 这是我有史以来的第一次尝试,我无法从txt文件读取到Windows 7中的node.jsterminal。使用窗口中的Node.js应用程序,我键入“node sample.js”和sample.js和sample.txt文件位于桌面上的文件夹中,但node.exe应用程序不读取文件。 另外我不知道它将如何知道目录path任何见解? 这是我的代码: var fs = require("fs"); console.log("Starting"); fs.readFile("sample.txt", function(error, data) { console.log("Contents of file: " + data); }); console.log("Carrying on executing");

meteor,错误:无法等服务器上使用Meteor.setTimeout()光纤

我对meteor相当陌生,所以我可能会错过这里的一个关键洞察。 无论如何,我想向用户指出同时有多less其他用户在网站上。 我有一个AuditItems集合,它已经存储了kv-pairs对于who , what when以及我可以用于这种types的计算。 我的Collections查询运行一个new Date()参数,所以我不能只是观察结果,我必须定期重新运行查询。 然后,我通过调用Deps.Dependency changed Deps.Dependency 。 这里是代码: // publishing counts of the users that are logged on // at the moment Meteor.publish("user-activity", function () { var self = this; self.added("user-activity", "all-recent-activity", {'operations': getRecentActivityCountsCache}); self.ready(); Deps.autorun(function() { self.changed("user-activity", "all-recent-activity", {'operations': getRecentActivityCounts()}); }); }); var getRecentActiveCountsDependency = new Deps.Dependency; var getRecentActivityCountsCache […]

节点js ENOENT错误

运行这个代码给我这个错误,试图找出一个小时,但失败 var http = require('http'); var url = require('url'); var fs = require('fs'); var port = 3010; http.createServer(function(req, res){ var query = url.parse(req.url,true).query; console.log(query); var file = query.f + query.t; //var file = "eurusd_m1.json"; console.log(file); var eurusd; fs.readFile('data/' + file + '_m1.json', function(err,data){ if (err){ console.log(err); } eurusd = JSON.parse(data); console.log(eurusd); }); res.writeHead(200,{'content-type':'text/plain'}); res.end("helllo owrld"); […]

Derby.js第一个新项目不起作用

我试图按照derbyjs.com上的教程。 npm install -g derby cd ~ derby new first-derby-project cd first-derby-project npm start 但是控制台输出这个: > first-derby-project@0.0.0 start /Users/User104/first-derby-project > node server.js Master pid 3603 3604 listening. Go to: http://localhost:3000/ events.js:72 throw er; // Unhandled 'error' event ^ Error: Redis connection to 127.0.0.1:6379 failed – connect ECONNREFUSED at RedisClient.on_error (/Users/User104/first-derby-project/node_modules/redis/index.js:163:24) at Socket.<anonymous> (/Users/User104/first-derby-project/node_modules/redis/index.js:86:14) at Socket.EventEmitter.emit […]

node-gyp:gyp ERR! 无法加载共享的libpython2.7.so.1.0

我正在尝试为节点js构buildhello world c ++插件。 node.js和node-gyp似乎都已成功安装到redhat linux中。 但是当我运行“node-gyp configure”时,它给出了以下错误。 我没有通过gooling和wiki页面获得任何有见地的信息。 你能恳请build议吗? 我从源代码构build了Python并进行了自定义安装。 下面是libpython2.7.so.1.0:$ PYTHONPATH以及$ LD_LIBRARY_PATH。 节点或节点gypsearch一个相当不同的环境可以共享库吗? 提前致谢。 堆栈错误: ~/examples/node.js/my_node_addon-1[13:14]% node-gyp configure gyp info it worked if it ends with ok gyp info using node-gyp\@0.10.10 gyp info using node\@0.10.18 | linux | x64 gyp ERR! configure error gyp ERR! stack Error: Command failed: python: error while loading […]

module.require有什么用途?

module.require的文档指出: module.require方法提供了一种加载模块的方法,就好像从原始模块中调用require() 。 文档对于这个目的是非常不透明的。 何时,如何,为什么我需要使用它?

在使用node-gyp构build时,无法将nodeJS本机C ++插件链接到与节点(0.10.18)静态绑定的OpenSSL

我读过这个: https : //github.com/TooTallNate/node-gyp/wiki/Linking-to-OpenSSL ,但由于某种原因,它不适合我。 当我试图要求从节点的插件时,我得到“未定义的符号:SHA1”。 这是我的代码( src/sha_export.cc ): #include <node.h> #include <node_buffer.h> #include <v8.h> #include <openssl/sha.h> using namespace v8; Handle<Value> Sha1(const Arguments& args) { HandleScope scope; if (args.Length() < 1) { ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); return scope.Close(Undefined()); } unsigned char*msg = (unsigned char*) node::Buffer::Data(args[0]->ToObject()); size_t msglen = node::Buffer::Length(args[0]->ToObject()); unsigned char dgst[20]; SHA1(msg, msglen, dgst); […]

我应该在哪里扩展Sails.js ServerResponse的原型?

Sails.js v0.9.4 Node.js v0.10.18 Express.js v3.2.6 我写了帆简单的Web应用程序。 我想为ServerResponse原型添加新的function,以便进行常见的错误响应,如下所示。 UtilService.js require('http').ServerResponse.prototype.returnError = function (message) { console.error("Error: " + message); return this.view("./error", { errors: [{ stack: message }] }); }; FooController.js require("../services/UtilService"); 以上代码运行良好。 但我不写所有控制器相同的片段。 我怎样才能保持干爽? 换句话说,我应该在上面的扩展代码上写哪个文件? 添加于2013-09-25 09:26 UTC 感谢您的build议和意见。 我给config/bootstrap.js添加了特殊的逻辑,因为我只想运行原型修改代码一次。 这看起来工作正常。 configuration/ bootstrap.js module.exports.bootstrap = function (cb) { cb(); require('http').ServerResponse.prototype.returnError = function (message) { console.error("Error: " […]