使用IIS托管Nodejs搭建Swagger(2)

使用IIS托管Nodejs搭建Swagger(1)介绍了怎样使用Nodejs搭建SwaggerUI。Nodejs搭建SwaggerUI成功后有一个问题。命令行不能关闭。关闭后等于Express服务关闭。可以使用IIS托管Nodejs处理这一问题。以下为配置步骤

 

1. IIS创建网站

填写网站基本参数。物理地址选择SwaggerUI的物理地址

 

2.下载并安装”iisnode”. 下载地址: https://github.com/tjanczuk/iisnode/wiki/iisnode-releases.(注意iisnode一定要在IIS 7.0或以上版本方能使用)

 

3.下载并安装”urlrewrite”.下载地址: http://www.iis.net/downloads/microsoft/url-rewrite

 

4. 安装完成”iisnode”和”urlrewrite”后在Swagger目录下添加”web.config”文件并输入以下配置

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <system.webServer>

     <!-- indicates that the hello.js file is a node.js application

    to be handled by the iisnode module -->

     <handlers>

        <add name="iisnode" path="index.js" verb="*" modules="iisnode" />

    </handlers>

   

    <rewrite>

            <rules>

                <rule name="all">

                    <match url="/*" />

                    <action type="Rewrite" url="index.js" />

                </rule>

            </rules>

    </rewrite>   

   

     <iisnode

        node_env="%node_env%"

        nodeProcessCountPerApplication="1"

        maxConcurrentRequestsPerProcess="1024"

        maxNamedPipeConnectionRetry="100"

        namedPipeConnectionRetryDelay="250"

        maxNamedPipeConnectionPoolSize="512"

        maxNamedPipePooledConnectionAge="30000"

        asyncCompletionThreadCount="0"

        initialRequestBufferSize="4096"

        maxRequestBufferSize="65536"

        watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade"

        uncFileChangesPollingInterval="5000"

        gracefulShutdownTimeout="60000"

        loggingEnabled="true"

        logDirectory="iisnode"

        debuggingEnabled="true"

        debugHeaderEnabled="false"

        debuggerPortRange="5058-6058"

        debuggerPathSegment="debug"

        maxLogFileSizeInKB="128"

        maxTotalLogFileSizeInKB="1024"

        maxLogFiles="20"

        devErrorsEnabled="true"

        flushResponse="false"

        enableXFF="false"

        configOverrides="iisnode.yml"

        nodeProcessCommandLine="C:\Program Files\nodejs\node.exe"

        promoteServerVars="REMOTE_ADDR" />

       

        <defaultDocument>

            <files>

                <add value="index.js" />

            </files>

        </defaultDocument>

 

    <security>

      <requestFiltering>

        <hiddenSegments>

          <add segment="node_modules" />

        </hiddenSegments>

      </requestFiltering>

    </security> 

 

  </system.webServer>

</configuration>

 

 5. 修改”index.js”文件为

var express = require('express');

var app = express();

app.use(express.static('public'));

app.use('/', function(req, res){

    res.write('You maybe access /v1/api');

    res.end();

});

 

/*app.listen(9444, function () {

 

         console.log('Example app listening on port 9444!');

 

});*/

 

app.listen(process.env.PORT);

启动刚创建的网站。然后打开浏览器查看结果

 

IIS托管成功 

posted @ 2019-03-13 16:59  Matrix博客园  阅读(465)  评论(0编辑  收藏  举报