0

I'm getting an error Cannot GET /nodetest/api/test when trying to connect to my node app using IIS with HttpPlatformHandler

enter image description here

What I did is add my node app in IIS -> Default Website -> Add Application then use the link http://localhost/nodetest/api/test to try the app

app.js

const express = require('express')
const app = express()

const port = process.env.PORT || 3001;

app.get('/api/test', function(req, res){
    return res.status(200).send('First Server');
})

app.listen(port, () =>{
    console.log(`Server is listening to ${port}.....`);
})

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
        <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\node.log" startupTimeLimit="20" processPath="C:\Program Files\nodejs\node.exe" arguments=".\app.js">
            <environmentVariables>
                <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
                <environmentVariable name="NODE_ENV" value="Production" />
            </environmentVariables>
        </httpPlatform>
    </system.webServer>
</configuration>

Content of nodetest application pool enter image description here

nodetest application settings enter image description here

Yuu
  • 619
  • 3
  • 13
  • 34
  • You provided too little information about your IIS setup. What is the physical path of that `web.config` file? What's the physical path you set in `Add Application` dialog? What's the name you gave to that new IIS application? – Lex Li Jul 08 '22 at 05:31
  • Hello, @LexLi I updated the content of my question. Thank you – Yuu Jul 08 '22 at 05:53
  • I tried to make a test by creating the new Node app and adding your code to it. I run it locally and make sure it works. After that, I try to host it as an application under the Default site. I am getting errors but not the same as yours. Further, I host the site by creating a new website in the IIS. I noticed that it works fine. For testing purposes, could you try to host your site as a new website and see whether it works? – Deepak-MSFT Jul 08 '22 at 09:57

1 Answers1

0

If you change your app.js as below, then it should work

const express = require('express')
const app = express()

const port = process.env.PORT || 3001;

app.get('/api/test', function(req, res){
    return res.status(200).send('First Server');
})

app.get('/nodetest/api/test', function(req, res){
    return res.status(200).send('as an IIS application');
})

app.listen(port, () =>{
    console.log(`Server is listening to ${port}.....`);
})
Lex Li
  • 60,503
  • 9
  • 116
  • 147