Question

I have some node.js code using jsdom and I need jquery.min.js file for backend css selector stuffs. Things ran fine locally but if I deploy using vmc push on api.cloudfoundry.com, it gave me 502 Bad Gateway nginx

I assume I have to declare all dependencies in package.json like here http://blog.nodejitsu.com/package-dependencies-done-right

However, I don't know how to include jquery.min.js. Right now it is in /lib folder and not /node_modules folder (because it's not a node module).

Can someone help me on how to include the right dependencies and other extra .js files for Cloud Foundry?

UPDATE 1:

Here is my code after removing bunch of things. If I commenting out the jsdom.env, there is no error.

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);

Here are what I saw when using 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

It can't be contextify because my localhost:3000 ran just fine https://github.com/tmpvar/jsdom/issues/436

Was it helpful?

Solution 2

I decided to go with Cheerio

That one works fine.

OTHER TIPS

window.document will return null in Cloud Foundry as it relies on an actual browser dom to be present on the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top