简体   繁体   English

在Azure的IISNode上调用本地主机URL

[英]Calling localhost urls on Azure's IISNode

I am running into some issues with running a Node app on Azure WebSites due to IISNode. 由于IISNode,我在Azure网站上运行Node应用程序时遇到一些问题。 Basically the issue is that I am relying on the port number being a number, which frankly is not the case on Azure ... Here the port number is actually a named pipe, and has values like \\\\.\\pipe\\76deda07-ef5c-4539-87d8-755ede772521 . 基本上,问题是我依赖的端口号是一个数字,坦率地说,在Azure上不是这样的。这里的端口号实际上是一个命名管道,其值类似\\\\.\\pipe\\76deda07-ef5c-4539-87d8-755ede772521 Thus, the following piece of code, which routes an internal request back onto the HTTP routes defined on localhost, does not work: 因此,以下将内部请求路由回本地主机上定义的HTTP路由的代码不起作用:

function getFromLocalRoute(restPayloadObject, callback) {

    request.get({
        uri : util.format('http://localhost:%s/api/%s', app.config.port, restPayloadObject.servicepath),
        json : true
    }, callback);
}

It should go without saying that this works fine on *nix systems, but now I need to find a nice way of handling this that works on Windows as well. 不用说,这在* nix系统上可以正常工作,但是现在我需要找到一种很好的方法来处理在Windows上也可以使用的方法。

What I am after is basically this: 我所追求的基本上是这样的:

  1. I have a url that exists on localhost 我有一个localhost上存在的URL
  2. I would like to call the url on localhost using this url 我想使用此URL在本地主机上调用URL
  3. It must work using IISNode 它必须使用IISNode才能工作

It does not have to use HTTP. 它不必使用HTTP。 I simply want to reuse the logic that is implicit by using Express to handle my routing logic, parsing everything, sending it on to the right modules, etc. So if there is a way of calling the Express Router without using HTTP that would be perfect. 我只想重用通过使用Express处理我的路由逻辑,解析所有内容,将其发送到正确的模块等的隐式逻辑。因此,如果有一种方法可以在不使用HTTP的情况下调用Express Router,那将是完美的。

Related: 有关:

Windows Azure Websites uses IISNode to host the Node process inside of IIS. Windows Azure网站使用IISNode在IIS中托管Node进程。 Your Node site is actually given a Named Pipe which receives the incoming requests, not a TCP port like you would use when running locally or hosting yourself. 实际上,为您的Node站点分配了一个命名管道,该管道接收传入的请求,而不是像在本地运行或托管自己时使用的TCP端口。 Even if you could open a TCP port, Azure Websites are really only meant for traditional websites and don't have a way to open ports to the outside world. 即使您可以打开TCP端口,Azure网站实际上也仅适用于传统网站,而无法打开通往外界的端口。

As we will get this error message like: Error: connect EACCES 127.0.0.1:80 at Object.exports._errnoException (util.js:837:11) at exports._exceptionWithHostPort (util.js:860:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14) 因为我们将收到以下错误消息: Error: connect EACCES 127.0.0.1:80 at Object.exports._errnoException (util.js:837:11) at exports._exceptionWithHostPort (util.js:860:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)

As a workaround, If your URL which is wanted is in your expressjs project, you can leverage res.redirect or custom build-in function to handle params. 解决方法是,如果所需的URL在expressjs项目中,则可以利用res.redirect或自定义的内置函数来处理参数。 Or you can migrate your project to Azure VM which offers greater flexibility for your need. 或者,您可以将项目迁移到Azure VM,这将为您提供更大的灵活性。

I posted another question that was related to this problem, and I found a decent programmatic solution that applies to this problem. 我发布了另一个与此问题有关的问题,并且找到了适用于此问题的不错的程序解决方案。

Turns out it is possible to call express.Router directly by using the (non-public/unofficial) Router#handle method with a stubbed out request and response object. 事实证明,可以使用带有残缺的请求和响应对象的(非公共/非官方) Router#handle方法直接调用express.Router For details on that approach you can refer to this answer . 有关该方法的详细信息,请参考此答案

It turned out that the named pipe approach was non-viable, so calling the Router directly seems like the closest fit for the problem at hand. 事实证明 ,命名管道方法是不可行的,因此直接调用路由器似乎是最适合当前问题的方法。

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

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