Running nodejs in iisnode getting http://localhost/node/polyfills.c466c90744ce632ac8b9.js net::ERR_ABORTED 500 (URL Rewrite Module Error.)

放肆的年华 提交于 2020-03-05 04:22:07

问题


I am trying to run node.js application in iisnode. I added an ssl certificate to IIS. Now I run theapplication in http and not https. When I start the application I see this error

net::ERR_ABORTED 500 (URL Rewrite Module Error.)

For all the static resources. I have enabled directory browsing for overall iisnode/www. I have ensured directory iisnode/www has full control to read/write for IIS_IUSRS group.

I am not familiar with writing rules or structuring web.config. Please help me to structure web.config. I have shown directory structure of iisnode/www here:

<configuration>
    <system.web>
        <customErrors mode="Off" />
        <httpCookies httpOnlyCookies="true" />
    </system.web>
   <system.webServer>
     <handlers>
       <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
     </handlers> 
     <rewrite> 
       <rules>
        <rule name="infrc">
          <match url="/*" />
          <action type="Rewrite" url="app.js" />
        </rule>
       </rules>
     </rewrite>
        <defaultDocument>
            <files>
                <clear />
                <add value="web.config" />
                <add value="app.js" />
                <add value="index.html" />
            </files>
        </defaultDocument>
        <directoryBrowse enabled="true" />
   </system.webServer>
 </configuration>




**app.js**
'use strict';
var express = require('express');
var http = require('http');
var fs = require('fs');
var path = require('path');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
const moment = require('moment');
require('dotenv').config();
var routes = require('./server/routes/index.route');
var config = require('./server/config/config');
var app = express();
morgan.token('user', (req, res) => {
  if (req.user) {
    return req.user.id;
  } else {
    return "Guest";
  }
});
morgan.token('timestamp', (req, res) => {
  return moment().format();
});
app.use(morgan(':timestamp :response-time :method :status :user :remote-addr :url'));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended : false }));
app.use(express.static(path.join(__dirname, '/client')));
app.get('/',function(req,res){  
  res.sendFile(path.join(__dirname, 'client/index.html'));
}); 


let port = 444;



function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'?'Pipe ' + port:'Port ' + port;

  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'?'pipe ' + addr: 'port ' + addr.port;
  console.log('Listening on ' + bind);
}


var server = http.createServer(app);
console.log(server);
app.set('port', port);
app.set('view engine', 'ejs');


server.on('error', onError);
server.on('listening', onListening);



const initializeDatabases = require('./server/dbs').initializeDatabases;
const crons = require('./server/routes/crons.js').crons;

initializeDatabases().then(dbs => {

    routes(app, dbs);
    server.listen(port);


}).catch(err => {
  console.error('Failed to make all database connections!');
  console.error(err);
  process.exit(1);
});



module.exports = app;

来源:https://stackoverflow.com/questions/56772770/running-nodejs-in-iisnode-getting-http-localhost-node-polyfills-c466c90744ce63

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!