Javascript node js POST mysite/上传404(未找到)时上传到azure,但在本地工作

Javascript node js POST mysite/上传404(未找到)时上传到azure,但在本地工作,javascript,html,node.js,azure,http-status-code-404,Javascript,Html,Node.js,Azure,Http Status Code 404,我正在为一个小网页做一个上传项目,我让它在本地工作,我可以上传文件,我可以操作它们,我可以得到必要的数据作为回应。我昨晚在azure上推了整件事,现在当我尝试上传我得到的东西时 POST mysite/uploads 404 (Not Found) My file.html <form id="uploadForm" enctype="multipart/form-data" action="/uploads" method="post"> <input type="fil

我正在为一个小网页做一个上传项目,我让它在本地工作,我可以上传文件,我可以操作它们,我可以得到必要的数据作为回应。我昨晚在azure上推了整件事,现在当我尝试上传我得到的东西时

POST mysite/uploads 404 (Not Found)
My file.html

<form id="uploadForm" 
enctype="multipart/form-data" action="/uploads" method="post">
<input type="file" name="userPhoto" class="btn btn-wire" />
<input type="submit" value="Upload" name="submit" class="btn btn-primary" />
</form>
nodeapp.js

app.use(multer({

dest: "./uploads",
onFileUploadStart: function (file) {
    console.log(file.originalname + ' is starting ...');  
},
onFileUploadComplete: function (file) {
    values = JSON.stringify(file);
    console.log(values);
    test.push({ "url": file.path, "filename": file.name, "fileType": file.extension });


}
}));
 app.post('/uploads'), function (req, res) {
        upload(req, res, function (err) {
            if (err) {
                return res.end("Error uploading the file!");
            }
            else {


                //res.json({ "test": "test123" });
                res.json(test)
                // res.write(JSON.stringify(test, null, 4));

                res.end();
                test = [];
            }
        })
    })

还有相当多的代码,但为了简单起见,以及我对项目这一特定部分的普遍怀疑,我只发布了这些代码片段

如何部署到Azure Web应用程序?在Azure Web应用程序上运行的As Node.js应用程序通过IISNode托管在IIS上。因此,在IIS上配置应用程序需要一个
web.config
文件

您可以在站点的根目录中检查此文件,看其配置是否正确

下面是一个
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="server.js" verb="*" modules="iisnode"/>
          </handlers>
          <rewrite>
               <rules>

                    <!-- Don't interfere with requests for node-inspector debugging -->
                    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                        <match url="^server.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="server.js"/>
                    </rule>

               </rules>
          </rewrite>
          <!-- You can control how Node is hosted within IIS using the following options -->
        <!--<iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade"/>-->
     </system.webServer>
</configuration>  


推送新路线后是否重新启动了应用程序?我觉得没有必要,因为它是第一次推送的,但在您发表评论后,我去重新启动了应用程序,没有任何更改。问题仍然存在。键入app.post('/upload'),即使我在app.use之外使用app.post,我仍然会收到相同的错误。app.post也应该在app.use之外(multer),因为在调用onFileUploadComplete和app.post之前,post路由/上载不存在(“/uploads…在每次文件上传完成时都会被重复调用,这是错误的。我通过git部署了它,并在正确的位置获得了web.config,配置正确,但我的POST和GET被禁用,因此在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="server.js" verb="*" modules="iisnode"/>
          </handlers>
          <rewrite>
               <rules>

                    <!-- Don't interfere with requests for node-inspector debugging -->
                    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                        <match url="^server.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="server.js"/>
                    </rule>

               </rules>
          </rewrite>
          <!-- You can control how Node is hosted within IIS using the following options -->
        <!--<iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade"/>-->
     </system.webServer>
</configuration>