如何在Windows Azure云项目中启动Node JS脚本? [英] How to start node js script in a windows azure cloud project?

查看:54
本文介绍了如何在Windows Azure云项目中启动Node JS脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是Node js和socket.io的新手.我正在将socket.io用于Windows天蓝色项目.我已经创建了一个启动socket.io服务器的App.js,但是我不知道如何以编程方式运行该脚本.我能够从"node app.js"之类的命令提示符下运行该脚本,socket.io服务器启动,并且客户端应用程序能够与socket.io服务器良好地交互.

Am very new to node js and socket.io. I am using socket.io for a windows azure project. I have created an App.js which starts the socket.io server, but i dont know how to programatically run that script. I am able to run that script from command prompt like "node app.js" and the socket.io server starts and the client app is able to interact with socket.io server well.

我还可以转到127.0.0.1/App.js,然后启动socket.io服务器.

I can also go to 127.0.0.1/App.js and the socket.io server starts.

但是我希望脚本在我在VS中启动项目后自动运行.关于我该怎么做的任何想法?

But I want the script to automatically run as soon as i start the project in my VS. Any idea on how i can do that?

原来iisnode可以处理所有事情,我只需要在web.config中放一个重写代码即可.从此处的示例azure节点js应用程序 http://www.windowsazure.com/zh-CN/develop/nodejs/tutorials/getting-started/我得到了这个重写代码

Turned out iisnode can handle everything , i just had to put a rewrite code in web.config. From a sample azure node js application from here http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/ i got this rewrite code

<rewrite>
  <rules>
    <clear />
    <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="iisnode.+" negate="true" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Rewrite" url="App.js" />
    </rule>
  </rules>
</rewrite>

它会自动启动App.js,但会将我的所有视图重新定向到App.js脚本.我想这与我上面写的代码有关.我应该进行哪些更改以使App.js在启动时运行并仍然能够访问我的其他html视图?

Its starting the App.js automatically, but its re directing all my views to the App.js script. I guess it has something to do with the re write code i put above. What changes should i make to get the App.js running on start up and still be able to access my other html views?

谢谢

推荐答案

好吧,根据您使用socket.io的原因,工作者角色可能更合适.WebRole当前不支持WebSockets,因此,如果您使用Web角色,则需要将传输设置为仅xhr-polling.

Well, depending on why you're using socket.io, worker role may be a better fit. WebSockets is not currently supported in WebRole, so you would need to set your transports to just xhr-polling if you used web role.

如果您只是对Web角色感兴趣,还可以考虑使用Azure网站来托管您的应用程序.您可以查看我的示例存储库,该存储库具有一个socket.io聊天应用程序,可以直接将其部署到azure网站上:

You can also consider using azure websites to host your app if you're just interested in a web role. You can check out my sample repo that has a socket.io chat app that can be deployed directly to azure websites:

http://github.com/markcowl/WebChatDefault-1

这篇关于如何在Windows Azure云项目中启动Node JS脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆