Using express on iisnode with an app.post yields a 404

0

I'm in the process of trying to move my node.js application from development to a hosted environment. It all works in dev, which is just running using npm start on my local machine. Now I'm migrating to a hosted iisnode instance and I'm missing something.
web.config

<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="*.njs" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
       <rules>
         <rule name="hello">
           <match url="hello/*" />
           <action type="Rewrite" url="hello.njs" />
         </rule>
                 <rule name="index_withSQL">
           <match url="ffbeReport/*" />
           <action type="Rewrite" url="index_withSQL.njs" />
         </rule>
       </rules>
     </rewrite>
         <security>
       <requestFiltering>
         <hiddenSegments>
           <add segment="node_modules" />
         </hiddenSegments>
       </requestFiltering>
     </security>
    </system.webServer>
</configuration>

index_withSQL.njs

const express = require("express");
const port=process.env.PORT || 3000
const app=express();
const fileUpload = require('express-fileupload');
const path = require("path");
app.use(express.urlencoded({extended: false}));
app.use(express.json());
app.use(express.static(__dirname));
app.use(fileUpload());
app.post('/upload', function(req, res) {
//process the uploaded data
});
app.get('/minimalIndex.*',function(req,res){res.sendFile(path.join(__dirname + '/minimalIndex.njs'));});
app.get('/personal.css',function(req,res){res.sendFile(path.join(__dirname+'/personal.css'));});
app.get('/fileFlattener.html',function(req,res){res.sendFile(path.join(__dirname+'/fileFlattener.html'));});
app.get('/uploaded.html',function(req,res){res.sendFile(path.join(__dirname+'/uploaded.html'));});
app.get('/',function(req,res){res.sendFile(path.join(__dirname + '/minimalIndex.html'));});
app.get('/ffbeReport*',function(req,res){res.sendFile(path.join(__dirname + '/minimalIndex.html'));});
app.get('/googleOAuthSuccess',function(req,res){res.sendFile(path.join(__dirname + '/minimalIndex.html'));});
app.get('/static/units.json',function(req,res){res.sendFile(path.join(__dirname + '/static/flattenedStaticUnits.json'));});
const webserver = app.listen(port,function(){console.log('Express web server is running...on ${port}');});

minimalIndex.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Upload Form</title>
<link rel="stylesheet" type="text/css" href="personal.css"/>

</head>
<body>
  <center>
    <H1>Upload your Units</H1><br>
    <fieldset>
      <div>Provide the units output file from the FFBE Sync tool</div>
     <form ref='uploadForm' 
      id='uploadForm' 
      action='/upload' 
      method='POST' 
      target="uploaded.html"
      encType="multipart/form-data">
        <input type="file" name="sampleFile" />
        <input type='submit' value='Upload!' />
    </form>     
  </center>

</body>
</html>

When I go to http://velgarth.w27.wh-2.com/minimalIndex.html, or /ffbeReport I get the minimal index page just fine. But when I try and upload a file I get an IIS error 404

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Detailed Error Information:
Module     IIS Web Core
Notification       MapRequestHandler
Handler    StaticFile
Error Code     0x80070002
Requested URL      http://velgarth.w27.wh-2.com:80/upload
Physical Path      E:\web\velgarth\upload
Logon Method       Anonymous
Logon User     Anonymous

My best guess is that the problem stems from the fact it's trying to run a file since it says that the Handler is StaticFile. But I really don't know which step I'm missing.

javascript
node.js
express
iisnode
asked on Stack Overflow Apr 2, 2020 by Plidian • edited Apr 3, 2020 by Plidian

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0