我有一些 node.js 代码正在使用jsdom
,我需要jquery.min.js
后端 css 选择器的文件。事情在本地运行良好,但如果我使用vmc push
on部署api.cloudfoundry.com
,它给了我502 Bad Gateway nginx
我假设我必须在 package.json 中声明所有依赖项,就像这里http://blog.nodejitsu.com/package-dependencies-done-right
但是,我不知道如何包含jquery.min.js
. 现在它在/lib
文件夹而不是/node_modules
文件夹中(因为它不是节点模块)。
有人可以帮助我了解如何为 Cloud Foundry 包含正确的依赖项和其他额外的 .js 文件吗?
更新 1:
这是我删除一堆东西后的代码。如果我注释掉jsdom.env
,则没有错误。
var port = (process.env.VMC_APP_PORT || 3000);
var host = (process.env.VCAP_APP_HOST || 'localhost');
var http = require('http');
var request = require('request'),
jsdom = require('jsdom');
http.createServer(function (req, res) {
request({ uri:'http://www.google.com' }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('Error when contacting the url')
}
jsdom.env({
html: body,
scripts: [
'lib/jquery.min.js'
]
}, function (err, window) {
});
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(body);
res.end('\n');
});
}).listen(port, host);
这是我在使用时看到的vmc logs hp-myapp
Using manifest file manifest.yml
Getting logs for hp-myapp #0... OK
Reading logs/staging.log... OK
[2012-12-18 03:06:27] Setting up temporary directories
[2012-12-18 03:06:27] Downloading application
[2012-12-18 03:06:27] Unpacking application
[2012-12-18 03:06:27] Staging application
[2012-12-18 03:06:28] # Logfile created on 2012-12-18 03:06:28 +0000 by logger.r
b/25413
[2012-12-18 03:06:28] Skipping npm support: npm-shrinkwrap.json is not provided
[2012-12-18 03:06:28] Creating droplet
[2012-12-18 03:06:29] Uploading droplet
[2012-12-18 03:06:30] Done!
Reading logs/stderr.log... OK
/var/vcap/data/dea/apps/hp-myapp-0-5bda6049e33af03b32b79777356c8d63/app/node_mod
ules/jsdom/lib/jsdom.js:178
features = JSON.parse(JSON.stringify(window.document.implementation._fea
^
TypeError: Cannot read property 'implementation' of undefined
at exports.env.exports.jsdom.env.processHTML (/var/vcap/data/dea/apps/hp-myapp-0-5bda6049e33af03b32b79777356c8d63/app/node_modules/jsdom/lib/jsdom.js:178:59
)
at Object.exports.env.exports.jsdom.env (/var/vcap/data/dea/apps/hp-myapp-0-
5bda6049e33af03b32b79777356c8d63/app/node_modules/jsdom/lib/jsdom.js:269:5)
at Request._callback (/var/vcap/data/dea/apps/hp-myapp-0-5bda6049e33af03b32b
79777356c8d63/app/app.js:23:9)
at Request.init.self.callback (/var/vcap/data/dea/apps/hp-myapp-0-5bda6049e3
3af03b32b79777356c8d63/app/node_modules/request/main.js:122:22)
at Request.EventEmitter.emit (events.js:91:17)
at Request.<anonymous> (/var/vcap/data/dea/apps/hp-myapp-0-5bda6049e33af03b3
2b79777356c8d63/app/node_modules/request/main.js:661:16)
at Request.EventEmitter.emit (events.js:115:20)
at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (/v
ar/vcap/data/dea/apps/hp-myapp-0-5bda6049e33af03b32b79777356c8d63/app/node_modul
es/request/main.js:623:14)
at IncomingMessage.EventEmitter.emit (events.js:115:20)
at IncomingMessage._emitEnd (http.js:366:10)
Reading logs/stdout.log... OK
它不能被上下文化,因为我localhost:3000
跑得很好https://github.com/tmpvar/jsdom/issues/436