Nowjs expressjs 3.0

纵饮孤独 提交于 2019-12-13 06:43:41

问题


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.



来源:https://stackoverflow.com/questions/10782832/nowjs-expressjs-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!