Tag: 快速

NodeJS与连接busboy错误,“TypeError:不能调用方法”的未定义“

我有这段代码: router.route("/post") .get(function(req, res) { … }) .post(authReq, function(req, res) { … // Get uploaded file var fstream req.pipe(req.busboy) req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { … var fileSuffix = mimetype.split("/")[1] // Get suffix, may not always be correct var tmpFileName = postCount + "." + fileSuffix var tmpFileURL = __dirname + "/tmp/" + […]

如何在交叉源请求中保留会话数据?

我是使用Express和Connect的新手,所以我希望我做一些简单的解决scheme愚蠢的东西… 基本上,我有一个用户使用Personalogin的页面。 为了validation身份validation尝试,我使用express-persona 。 假设这个模块将用户的validation邮件地址保存在一个会话variables(req.session.email,默认)中。 现在,login后,用户可以发表评论,这个评论将与用户login的电子邮件地址一起保存。当服务表单的服务器与处理发表评论的服务器相同时,这工作正常。 然而,当它们不同时(比如说用户填写http://localhost:8001的表单,而浏览器则发送一个POST请求到http://localhost:8000这个应该保存注释),所有的突然req.session.email值是undefined 。 我认为我正确设置了跨源资源共享。 表单是这样发送的(使用jQuery): $.ajax('http://localhost:8000/post/comment', { data: {comment: $('#commentField').val()}, type: 'POST', xhrFields: {withCredentials: true} } ); (注意xhrField: {withCredentials: true} – 会话cookie被传递,我通过检查networking请求来validation。) 服务器设置(我认为)正确的CORS标题: res.header('Access-Control-Allow-Origin', 'http://localhost:8001'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'); res.header('Access-Control-Allow-Credentials', 'true'); 当我添加console.log(req.cookie) ,我看到sessionId cookie与POST请求一起发送的值相同。 但是: console.log(req.session.email)显示undefined的跨源请求 – 再一次,当请求来自同一个来源时,它工作正常。 我究竟做错了什么?

同步使用Node.js下载N个远程文件

我正在使用一个简单的应用程序使用Node.js需要执行以下操作时给予一个有效的URL 检索远程页面的HTML,保存在本地。 蜘蛛的HTML(使用cheerio)并logging所有的JS和CSS文件引用。 为每个JS / CSS文件创buildHTTP请求并通过文件名将其保存到服务器。 压缩html,css和js文件并将结果文件stream式传输到浏览器。 我有1和2个工作,而#3的前半部分,但我遇到的下载同步性的问题。 我的代码运行得太快,为CSS和JS文件生成文件名,但没有任何内容。 我猜这是因为我的代码不同步。 问题是,我不能预先知道有多less文件可以在ZIP文件生成之前,所有文件都必须在那里。 这是我的应用程序的stream程,因为它目前存在。 我省略了辅助方法,因为它们不会影响同步性。 你们能提供什么我应该做的input吗? http.get(fullurl, function(res) { res.on('data', function (chunk) { var $source = $(''+chunk), js = getJS($source, domain), css = getCSS($source, domain), uniqueName = pw(), dir = [baseDir,'jsd-', uniqueName, '/'].join(''), jsdir = dir + 'js/', cssdir = dir + 'css/', html = rewritePaths($source); // […]

Node.js:res.redirect(“back”)得到错误('不能在发送之后设置头部')。

我有一个express.js应用程序的一个小问题。 在使用callback进行多个操作后,无法重新导向。 我的应用程序使用名为“标记”的对象,并按“子类别”进行评分。这些操作的目标是合并2个或更多个子类别,将所有标记从旧类别移动到新子类别,最后删除旧的子类别。 这里是代码: 检查2个或更多子类别后调用的操作: exports.postMergeSubCategories = function(req, res) { "use strict"; var data = {}; data.subCategories = req.body.subCategoriesChecked; data.enName = req.body.subCategory.enName; data.frName = req.body.subCategory.frName; data.deName = req.body.subCategory.deName; if (data.subCategories.length > 1) { sscategoryMapper.merge(data, function(err, sscategory) { if (err) return console.log(err); console.log ('Sub categories merged !'); req.flash('mergeMessage', 'Merge completed!'); res.redirect("back"); }); } else { // […]

stream节点fluent-ffmpegstreammp4video

我正在尝试创buildvideostream服务器和客户端节点fluent-ffmpeg , express和ejs 。 而且有一段时间没有解决这个问题。 我想要做的是从一定时间开始播放video。 下面的代码使用Safari浏览器在Windows上,但与其他人做了几秒钟的循环或说 不支持video格式 服务器代码(run.js) : app.get('/video', function(req, res) { //define file path,time to seek the beegining and set ffmpeg binary var pathToMovie = '../videos/test.mp4'; var seektime = 100; proc.setFfmpegPath(__dirname + "/ffmpeg/ffmpeg"); //encoding the video source var proc = new ffmpeg({source: pathToMovie}) .seekInput(seektime) .withVideoBitrate(1024) .withVideoCodec('libx264') .withAspect('16:9') .withFps(24) .withAudioBitrate('128k') .withAudioCodec('libfaac') .toFormat('mp4'); //pipe […]

在Hapijs后端处理由Alamofire在Swift中发送的多部分/表单数据请求

我正在使用swift创build一个图像和video上传iOS应用程序。 我正在使用Alamofire库进行networking请求。 下面是用户select图像时快速运行的代码 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { dismissViewControllerAnimated(true, completion: nil) guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else { print("Did not get required image") return } guard let imageData = UIImageJPEGRepresentation(image, 0.8) else { return } Alamofire.upload(.POST, "http://localhost:8101/upload_request", multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(data: imageData, name: "image") }, encodingCompletion: { encodingResult […]

MongoDB – MongoError:连接ECONNREFUSED

尝试连接mongoDB时,我不断收到错误。 我知道有很多类似于这个问题的问题,我已经检查了所有这些问题,还没有find解决我的问题。 这是确切的错误: 连接错误:{MongoError:连接ECONNREFUSED 127.0.0.1:21017名称:'MongoError'消息:连接ECONNREFUSED 127.0.0.1:21017 我看了一些其他的解决scheme,他们说调整mongo.conf文件,但我似乎无法find我的系统上的文件,我已经下载了MongoDB。 这是我的完整代码: var express = require('express'); var router = express.Router(); var mongoose = require('mongoose'); $ = require('cheerio'); /* GET home page. */ mongoose.connect('mongodb://localhost/'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function() { console.log('Connected to database'); // we're connected! }); var pageInfo = { title: 'JotIT', owner: 'Emmanuel […]

我可以使用APNauthentication密钥.p8文件与PHP发送iOS推送通知?

我的推送通知停止与最近的更新之一。 当我进一步研究它时,我发现苹果现在可以让你生成一个非失效的APNsauthentication密钥,它可以用于生产和testing。 我有它使用下面的node.js脚本: var apn = require('apn'); // Set up apn with the APNs Auth Key var apnProvider = new apn.Provider({ token: { key: 'apns.p8', // Path to the key p8 file keyId: '<my key id>', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key) teamId: '<my team id' // The Team ID […]

在所有日志中打印bunyan中间件reqId

我正在开发一个RESTful服务,使用节点,快递和bunyan中间件。 Bunyan中间件正在生成一个UUID,在req.reqId中也是一样的。 所以,当日志logging通过req.log.info(“log message”)发生时,reqId将被打印在日志中。 但是我面临的问题是,有许多内部帮助者没有req的上下文。 一个解决scheme是将req对象传递给每个函数,但这看起来像是一个开销。 欣赏任何解决scheme。

清理closuresexpress.js + mongodb服务器(使用node.js)

我有使用express.js和mongodb作为数据存储的node.js web服务器。 这台服务器是由runit控制的,我试图实现一种正常closures服务器的方式。 我正在为SIGINT和SIGTERM实现信号处理程序,并且我知道可以通过调用createServer()返回的对象上的.close()来停止监听新连接。 到现在为止还挺好。 但是,即使没有更多的请求即将到来,系统中可能还有很多请求需要完成,然后才能closures数据库。 我正在使用一个mongodb ReplicaSet,我想如果我只是立即调用db.close() ,这些请求中的一些可能会以某种方式失败。 是否有某种方式来closures数据库的方式,使待完成的数据库查询完成,或者我必须手动有一个+/-计数器,看看有多less“活动”查询挂起,然后等待关机,直到它达到0 ?