iisnode托管的Web应用程序可以解决托管的虚拟路径吗? [英] Can an iisnode-hosted web application work out the virtual path at which it is hosted?

查看:205
本文介绍了iisnode托管的Web应用程序可以解决托管的虚拟路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iisnode 在Windows上的IIS中托管节点Web应用程序。当我在Web服务器上设置路由(比如说Express或Restify)时,我想做的就是独立于IIS承载该应用程序的路径。



例如,我的应用程序可以在运行IIS的两台计算机上的两个不同路径上托管;第一个可以在 / foo 托管它,第二个可以在 / bar 上托管。说我的应用程序想在 / baz 上设置路由 - 在第一台机器上,我需要在 / foo / baz 而在第二个我将不得不使用 / bar / baz 这意味着重复IIS中保留的一些配置。



是否可以从使用iisnode托管的应用程序中可靠地编制路径,以便我可以计算正确的路由设置?还是有另一种技术可以避免需要这样做?

解决方案

我不知道有什么办法可以避免看到对应于您在iisnode中托管的node.js应用程序中的虚拟目录的路径段。确保您的应用程序代码与主机无关的最佳方法是将其托管在IIS网站的根目录下。


I am using iisnode to host a node web application in IIS on Windows. When I set up my routes on the web server (say Express or Restify) I want do do it in a way that is independent of the path that IIS is hosting the application at.

For example, my application could be hosted at two different paths on two machines running IIS; the first could host it at /foo and the second at /bar. Say my application wants to set up a route at /baz - on the first machine I would need to configure the route at /foo/baz and on the second I would have to use /bar/baz which means duplicating some of the configuration held in IIS.

Is it possible to reliably work out the path from within an application hosted with iisnode so that I can calculate the correct routes to set up? Or is there another technique I can use to avoid needing to do so?

解决方案

I am not aware of a way to avoid seeing the path segment corresponding to the virtual directory within your node.js application hosted in iisnode. The best way to ensure your application code is host agnostic is to host it at the root of an IIS web site.

这篇关于iisnode托管的Web应用程序可以解决托管的虚拟路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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