Nowjs expressjs 3.0

2019-09-01 06:22发布

问题:

I´m trying to get nowjs to work with expressjs 3.0alpha4. I´ve added the script to my view like so:

<script src="/nowjs/now.js"></script>

And have also tried:

<script src="https://localhost/nowjs/now.js"></script>

But all i get is a:

GET https://localhost/nowjs/now.js 403 (Forbidden)

Have anyone gotten this to work with expressjs 3.0.?

Even if i host the now.js file, I still get: Now is not defined

回答1:

You need to pass an HTTPServer object to the now initializer. Express 3.0 doesn't reveal this object like 2.x did.

So do something like:

var server = http.createServer(app).listen(app.get('port'), function() {
  console.log('Express server listening on port ' + app.get('port'));
}

var everyone = require('now').initialize(server);


回答2:

First check if you have your static middleware setup.

app.use( express.static(__dirname + '/public' ) )

Second make sure you put your nowjs directory inside the public directory with the now.js file inside the nowjs directory.