Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用azure应用程序服务的Nodejs Express路由器REST API_Node.js_Azure_Iisnode - Fatal编程技术网

Node.js 使用azure应用程序服务的Nodejs Express路由器REST API

Node.js 使用azure应用程序服务的Nodejs Express路由器REST API,node.js,azure,iisnode,Node.js,Azure,Iisnode,我的azure帐户中有一个应用程序服务,它运行一个节点应用程序(Express、Angular和websockets)。我可以为我的用户提供静态内容,但是RESTAPI失败,出现404未找到错误 以下是我在index.js中的代码 var os = require('os'); var fs = require("fs"); var bodyParser = require('body-parser'); var express = require('express'), express

我的azure帐户中有一个应用程序服务,它运行一个节点应用程序(Express、Angular和websockets)。我可以为我的用户提供静态内容,但是RESTAPI失败,出现404未找到错误

以下是我在index.js中的代码

var os = require('os');
var fs = require("fs");
var bodyParser = require('body-parser');
var express = require('express'),
    expressApp = express(),
    socketio = require('socket.io'),
    http = require('http'),
    uuid = require('node-uuid'),
    config = require('../config/config.json');

var httpServer = http.createServer(expressApp),
    rooms = {},
    userIds = {};
expressApp.use(express.static(__dirname + '/../public/dist/'));
expressApp.use(bodyParser.urlencoded({ extended: true }));
expressApp.use(bodyParser.json());
var router = express.Router();
expressApp.use('/api', router);
router.get('/getsomethings', function(req, res) {
    res.json(something);
});
expressApp.use('/api', router);
expressApp.listen = function listen() {
    httpServer.listen(config.PORT);
};

expressApp.listen();
exports.run = function(config) {

    //some code
};
下面是app.service的web.config

<configuration>
  <system.webServer>

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

    <rewrite>
      <rules>        
        <!-- Don't interfere with requests for node-inspector debugging -->
        <clear />
        <rule name="Redirect to https" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
        </rule>

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

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}" />
        </rule>
        <!-- All other URLs are mapped to the Node.js application entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
          </conditions>
          <action type="Rewrite" url="index.js" />
        </rule>
      </rules>
    </rewrite>
    <security>
       <requestFiltering>
         <hiddenSegments>
           <add segment="node_modules" />
         </hiddenSegments>
       </requestFiltering>
     </security>
    <!-- You can control how Node is hosted within IIS using the following options -->
    <!--<iisnode      
          node_env="%node_env%"
          nodeProcessCountPerApplication="1"
          maxConcurrentRequestsPerProcess="1024"
          maxNamedPipeConnectionRetry="3"
          namedPipeConnectionRetryDelay="2000"      
          maxNamedPipeConnectionPoolSize="512"
          maxNamedPipePooledConnectionAge="30000"
          asyncCompletionThreadCount="0"
          initialRequestBufferSize="4096"
          maxRequestBufferSize="65536"
          watchedFiles="*.js"
          uncFileChangesPollingInterval="5000"      
          gracefulShutdownTimeout="60000"
          loggingEnabled="true"
          logDirectoryNameSuffix="logs"
          debuggingEnabled="true"
          debuggerPortRange="5058-6058"
          debuggerPathSegment="debug"
          maxLogFileSizeInKB="128"
          appendToExistingLog="false"
          logFileFlushInterval="5000"
          devErrorsEnabled="true"
          flushResponse="false"      
          enableXFF="false"
          promoteServerVars=""
         />-->

  </system.webServer>
</configuration>

当我访问我的站点时,除了/getsomethings XHR给出404错误之外,一切都正常。所有的静态内容都很好

有人能帮我找出问题出在哪里吗?

你说“我可以为我的用户提供静态内容”,因为你在
web.config
中有这个

<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
    <action type="Rewrite" url="public{REQUEST_URI}" />
</rule>
另外,请尝试更改以下代码行:

httpServer.listen(config.PORT);
致:


是的,这就是我的文件夹结构。但是我无法获取任何对/api url的请求。我试图在我的web.config中添加/api url的规则,但我想我的web.config中缺少了一些内容。您的web.config文件很好。我测试过了。您可能需要帮助解决此问题。非常感谢@Aaron,我不知道我可以以这种方式启用iisnode登录。这肯定会对我有很大帮助。它终于对我起作用了。谢谢,代码没有问题。我刚刚删除了我的index.js并重新添加了它,它的效果非常好。但是你关于启用日志记录的评论对我跟踪其他事情有很大帮助。
httpServer.listen(config.PORT);
httpServer.listen(process.env.PORT || config.PORT);