Tag: 表示

为什么expressjs每个OPTIONS响应都发送Set-Cookie头?

我发现我的快递服务器发送了一个Set-Cookie头,以响应我的前端Angular.js项目所做的每个OPTIONS请求。 这个cookie在每个OPTIONS请求上都有一个新的值,但实际上从来没有被Chrome存储过。 当我使用passport.js来validation用户时,对POST请求的响应具有相同的头(同样是一个新的cookie),但是这次我可以看到它被存储,并随后在Cookie头中发送请求。 哪个expression模块正在做这个,为什么? 为什么Chrome不存储cookie? 这比任何东西都更好奇,因为它不会造成任何问题(当试图追踪一个问题时引起了很多混乱)。

closures连接而不是设置“保持活动”

我试图在一个非常简单的express应用程序禁用keep-alive设置。 我尝试了一个老版本的同样的答案 : var express = require('express'); var app = express(); app.get('/', function(req, res) { res.set('Connection', 'close'); // attempting to override default (keep-alive) res.set('Proof', 'close'); // just to show that this should modify the header value res.send('hello'); }); var server = app.listen(3000, function() { console.log('Listening on port %d', server.address().port); }); 但是, Connection仍然设置为keep-alive : $ curl […]

如何在NodeJS中获取Instagram用户名和权限

我正在使用Instagram的护照login到我的应用程序。 如何在用户login后获取用户名和访问令牌? 我无法访问中间件部分中的“configuration文件”。 //serialize user in the session passport.serializeUser(function (user, done) { done(null, user); }); //deserialize user in the session passport.deserializeUser(function (id, done) { User.findById(id, function (err, user) { done(err, user); }); }); //callback after successfull login of instagram exports.callback = function (req, res) { // Successful authentication, redirect home. console.log('calling'); var code = req.query.code; […]

带有vhost的Node.js / Express与Sails.js框架应用程序冲突

我试图设置我的Nodejs / Express托pipe服务器有多个应用程序(Sails.js应用types)在我的VPS上运行,但我得到这个错误: /srv/data/web/vhosts/default/node_modules/vhost/index.js:78 throw new TypeError('argument server is unsupported') ^ TypeError: argument server is unsupported at createHandle (/srv/data/web/vhosts/default/node_modules/vhost/index.js:78:9) at vhost (/srv/data/web/vhosts/default/node_modules/vhost/index.js:39:16) at Object.<anonymous> (/srv/data/web/vhosts/default/server.js:46:9) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3 当然,我以前安装了所有的依赖项。 我为多个应用程序的Nodejs / Express基本configuration是好的,因为它适用于这个快速虚拟主机示例configuration: https://github.com/loicsaintroch/express-vhosts 所以在这里我的nodejs服务器应用程序结构: …/vhosts/default/server.js package.json /app1 /app.js […]

我得到“断言失败:查询API时,必须在传递给”push“的散列中包含”id“

我必须阅读关于我的问题堆栈溢出的每一个问题,并没有find一个解决scheme。 我对Ember和Node很新,所以请耐心等待。 服务器以这种格式响应: { "_id" : "53fddf59d72f9b4d3a3e164a" "about" : [ {"from" : "foo"}, {"text" : "bar"}, … ] } 我的模型看起来像这样: App.About = DS.Model.extend({ from : DS.attr('string'), text : DS.attr('string'), … } 适配器和序列化器: App.ApplicationAdapter = DS.RESTAdapter.extend({ host: 'http://localhost:3000' }); App.ApplicationSerializer = DS.JSONSerializer.extend({ primaryKey: '_id' }); 而我的路线: App.AboutRoute = Ember.Route.extend({ model: function() { return this.store.find('about'); } }); […]

Node.js – require()d模块的范围是什么?

我试图组织一个使用Express 4开发的Node.js应用程序,并且对使用require()导入的模块范围感到困惑。 想象一下,我使用require('./services/user')来导入一个模块,比如routes / user.js中的服务 : var userService = require('./services/user'); 然后我在另一个模块routes / department.js中执行相同的require('./services/user') 。 我的问题是:userService是user.js和department.js中的同一个实例还是每个都有自己的userService对象? 也就是说,一旦你通过module.exports = XXX导出了一些元素,如果你需要相同的文件,你会总是得到相同的实例吗? 你能告诉我在哪里指定的Node.js文档?

在快速响应对象上获取Cookie数据?

我只是做了一些APItesting,我试图validation发送的cookie数据是正确的,但是我找不到有关从响应对象获取cookie的任何文档,只能从请求中获取。 那么是否有一个快速的方法来做到这一点,就像你会做的请求req.cookies["myCookie"] ,我知道我可以得到标题,并从那里得到一个集的cookie,但它有点混乱试图从那里手动parsing出来的cookie数据。

mongoose – 创build和插入数据到新的集合

现在我是MEAN.io的初学者。 我正在使用mongoose将数据插入到数据库。 我遵循这里的代码。 在我的app.js var mongoose = require('mongoose'); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; var Factory = require('./module.factory.js'); mongoose.connect('mongodb://localhost/angular'); var db = mongoose.connection; var dbCollection = db.collections; var factory = new Factory(Schema,mongoose); factory.createSchemas(); 在module.factory.js var Factory = function(Schema,mongoose) { this.Schema = Schema; this.mongoose = mongoose; this.Item = null; this.createSchemas = function() { var […]

节点的JS是asynchronous读/写安全?

可能是一个愚蠢的问题,但是如果程序asynchronous地写入文件,并且在文件还在写入的时候访问该文件,那么内容是否会混淆?

Express:服务预压缩的静态资产

我想预先压缩我的静态资产(不包括图片)并提供服务。 为了提供public文件夹,我有: app.use(express.static('path/to/public/')); 我相信express.compress()在即时压缩,这似乎是静态资产的服务器CPU上不必要的负担。 什么是达到这个标准的方法?