发布套接字应用程序后服务器返回404错误

时间:2019-04-23 11:45:00

标签: react-native iis websocket socket.io web-config

我正在使用socket-io开发一个简单的本机聊天应用程序。当我在IIS服务器中发布代码时,它返回404错误。我不知道是什么导致了这个问题。我尝试了许多解决方案,但仍然面临相同的问题。请为我提供一些解决此问题的方法。

我正在使用Windows Server 2012 R2。 IIS版本-8.5

****** node version - 10.15.3 *****
****** npm version - 6.4.1   ******                                                                                                                          

** server.js **

   const express = require('express');
   const http = require('http');
   const socketio = require('socket.io');
   const port = process.env.PORT || 4001;
   const fetch = require('node-fetch');
   const app = express();
   const server = http.createServer(app);
   const io = socketio(server);

   io.sockets.on('connection', socket => {    
       console.log("connected");
   });

   server.listen(port, () => console.log(`Listening on port ${port}`));

web.config

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

<configuration>
<appSettings>
<!--
<add key="StorageAccountName" value="" />
<add key="StorageAccountKey" value="" />
<add key="ServiceBusNamespace" value="" />
<add key="ServiceBusIssuerName" value="" />
<add key="ServiceBusIssuerSecretKey" value="" />
-->
</appSettings>
<system.webServer>

<webSocket enabled="false" />
 <!-- mimeMap enables IIS to serve particular file types as specified by fileExtension. -->
<staticContent>
<remove fileExtension=".svg" />
  <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>

<modules runAllManagedModulesForAllRequests="false" />

<!-- Web.Debug.config adds attributes to this to enable remote debugging when publishing in Debug configuration. -->
<iisnode watchedFiles="web.config;*.js" debuggingEnabled="true"/>   />

<!-- Remote debugging (Azure Website with git deploy): Comment out iisnode above, and uncomment iisnode below. -->
<!--<iisnode watchedFiles="web.config;*.js"
  loggingEnabled="true"
  devErrorsEnabled="true"
  nodeProcessCommandLine="node.exe &#45;&#45;debug"/>-->

<!-- indicates that the server.js file is a Node.js application 
to be handled by the iisnode module -->
<handlers>
  <add name="iisnode" path="server.js" verb="*" modules="iisnode" />

  <!-- Remote debugging (Azure Website with git deploy): Uncomment NtvsDebugProxy handler below.
  Additionally copy Microsoft.NodejsTools.WebRole to 'bin' from the Remote Debug Proxy folder.-->
  <!--<add name="NtvsDebugProxy" path="ntvs-debug-proxy/c4784c6b-c0f6-4698-b8b2-d152344934e2" verb="*" resourceType="Unspecified"
    type="Microsoft.NodejsTools.Debugger.WebSocketProxy, Microsoft.NodejsTools.WebRole"/>-->
</handlers>
<rewrite>
  <rules>
    <clear />
    <!-- Remote debugging (Azure Website with git deploy): Uncomment the NtvsDebugProxy rule below. -->
    <!--<rule name="NtvsDebugProxy" enabled="true" stopProcessing="true">
      <match url="^ntvs-debug-proxy/.*"/>
    </rule>-->
    <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="iisnode.+" negate="true" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
      <action type="Rewrite" url="server.js" />
    </rule>
    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^server.js\/debug[\/]?" />
    </rule>
    <rule name="Application">
      <action type="Rewrite" url="server.js"/>
    </rule>
     </rules>
    </rewrite>
     </system.webServer>

       <!-- Remote debugging (Azure Website with git deploy): uncomment system.web below -->
    <!--<system.web>
     <httpRuntime targetFramework="4.5"/>
    <customErrors mode="Off"/>
   </system.web>-->
 </configuration>

0 个答案:

没有答案