简体   繁体   English

iisnode和快递

[英]iisnode and express

I'm sure this question has been asked a million times but I've not found any solution to the following problem as of yet. 我确定这个问题已被问了一百万次,但我还没有找到解决以下问题的方法。

I have a basic application running using nodejs and express. 我有一个使用nodejs和express运行的基本应用程序。 When I run the application in node, it by default sends me to the index.html in my public folder. 当我在节点中运行应用程序时,它默认将我发送到我公共文件夹中的index.html。 Even if I don't have any routes set up. 即使我没有设置任何路线。 I want this to happen. 我希望这发生。

I've installed iisnode and created a new application under 'Default Website' called 'Devices'. 我安装了iisnode并在'Default Website'下创建了一个名为'Devices'的新应用程序。 I put my application in there unchanged. 我把我的申请保持不变。 Reading around I needed to sort some stuff out with the web.config and decided to go with the config mentioned here (not the yaml): 阅读我需要用web.config排序一些东西,并决定使用这里提到的配置(而不是yaml):

http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html

When I try and load the app up in my browser it always tries to find the route in my app.js and throws messages back at me such as: 当我尝试在浏览器中加载应用程序时,它总是尝试在我的app.js中找到路径并向我发送消息,例如:

Cannot GET /devices/ 无法获取/设备/

I'm really pulling my hair out with this one and don't know what to do! 我真的用这个把头发拉出来,不知道该做什么! Do I have to set up a default route for static content inside of my app.js entry point? 我是否必须在app.js入口点内为静态内容设置默认路由? I have the following in place: 我有以下内容:

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

But it still doesn't hand me over to index.html when I load the application from it's root: 但是当我从它的根加载应用程序时,它仍然没有把我交给index.html:

'http://localhost/devices/' 的 'http://本地主机/设备/'

Anyone able to help me out with this? 有人能帮我解决这个问题吗?

The easiest way to address this problem is to create a dedicated IIS website for your application as opposed to creating an IIS application within an IIS website like you did. 解决此问题的最简单方法是为您的应用程序创建专用的IIS网站,而不是像在IIS网站中那样创建IIS应用程序。

If you have a dedicated website for your node.js application in IIS, the application is accessible at the root of the URL space, eg http://myapp.com/ , which is what the default express route configuration expects. 如果您在IIS中有node.js应用程序的专用网站,则可以在URL空间的根目录访问该应用程序,例如http://myapp.com/ ,这是默认的快速路由配置所期望的。 In contrast, if you create an IIS application within an IIS website to host your node.js application (say devices ), it is accessible at a URL subordinate to the root URL of the web site, eg http://myapp.com/devices/ . 相反,如果您在IIS网站中创建IIS应用程序来托管您的node.js应用程序(比如devices ),则可以从该网站的根URL下属的URL访问它,例如http://myapp.com/devices/ The extra URL path segment ( devices ) is something your express app does not expect and is not configured to process, and therefore it rejects the request. 额外的URL路径段( devices )是您的快速应用程序不期望并且未配置为处理的内容,因此它拒绝该请求。

If you insist on hosting the node.js application as an IIS application in IIS, you will need to augment your express route configuration to expect the extra URL path segment that matches the IIS application name. 如果您坚持将node.js应用程序作为IIS中的IIS应用程序托管,则需要扩充快速路由配置以期望与IIS应用程序名称匹配的额外URL路径段。

A good suggestion can be found at: Can an iisnode-hosted web application work out the virtual path at which it is hosted? 可以在以下位置找到一个好的建议: iisnode托管的Web应用程序是否可以在其托管的虚拟路径上运行? Essentially, you use one small variable to abstract the path and an environment variable (if it exists) to control it. 实质上,您使用一个小变量来抽象路径和一个环境变量(如果它存在)来控制它。 Another good post (possibly better solution) can be found at https://github.com/tjanczuk/iisnode/issues/160 另一个好帖子(可能更好的解决方案)可以在https://github.com/tjanczuk/iisnode/issues/160找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM