节点js POST mysite / uploads 404(未find)上传到天青,但本地工作

我正在为一个小型网页上传一个上传项目,我把它们全部在本地工作,我可以上传文件,我可以操纵它们,我可以得到必要的数据作为回应。 昨天晚上我把所有东西都推到了azure,现在当我尝试上传我得到的东西的时候

POST mysite/uploads 404 (Not Found) 

我的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> 

HTML的file.js

 jQuery(document).ready(function () { $('#uploadForm').submit(function () { $("#status").empty().text("File is uploading..."); $(this).ajaxSubmit({ error: function (xhr) { $("#status").text('Error: ' + xhr.status); //alert(JSON.stringify(xhr)); }, success: function (response) { // var test = JSON.stringify(response[1], null, 4); // console.log(JSON.stringify(response, null, 4)); files = []; $(response).each(function (index) { files.push(response[index]); }) refreshFiles(); alert("alertsuccess"); $("#status").empty().text("File is uploaded..."); } }); return false; }); }); 

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 Apps上运行的Node.js应用程序通过IISNode托pipe在IIS上。 所以有一个web.config文件需要在IIS上configuration你的应用程序。

您可以在您的站点的根目录中检查此文件,无论它是否处于正确的configuration。

这是一个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>