IIS服务器中的Host Nodejs应用程序

时间:2017-03-20 10:57:41

标签: node.js express iis-7 web-config iisnode

我使用iisnode在IIS服务器上托管了一个NodeJs express应用程序。应用程序正在节点服务器上运行而不会出现任何错它给了我跟iisnode的错误。 使用的Express版本是4.13.4。

enter image description here

我已经为IIS安装了URL重写模块。

我的server.js文件如下。

'use strict';

// Module dependencies.
var express = require('express'),
    path = require('path'),
    fs = require('fs'),
    cors = require('cors'),
    methodOverride = require('method-override'),
    morgan = require('morgan'),
    bodyParser = require('body-parser');

var app = module.exports = exports.app = express();

app.locals.siteName = "IOS IBE";
app.use(cors());
//cors and preflight filtering
app.all('*', function (req, res, next) {
//preflight needs to return exact request-header
    res.set('Access-Control-Allow-Headers',
        req.headers['access-control-request-headers']);
    if ('OPTIONS' == req.method)
        return res.send(204);
    next();
});
app.use(express.static(__dirname + '/public'));

app.get('/*', function (req, res) {
    res.sendFile(__dirname + '/public/index.html');
});

app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

// Start server
var port = 4015;
app.listen(port, function () {
    console.log('Distributor portal App manager server listening on port %d in %s mode', port, app.get('env'));
});

我的web.conf如下

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>         
      <handlers>
           <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
     </handlers>
      <rewrite>
           <rules>

                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                    <match url="^server.js\/debug[\/]?" />
                </rule>

                <rule name="StaticContent">
                     <action type="Rewrite" url="public{REQUEST_URI}"/>
                </rule>

                <rule name="DynamicContent">
                     <conditions>
                          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                     </conditions>
                     <action type="Rewrite" url="server.js"/>
                </rule>

           </rules>
      </rewrite>
   </system.webServer>
 </configuration>

0 个答案:

没有答案