I'm getting an error Cannot GET /nodetest/api/test
when trying to connect to my node app using IIS with HttpPlatformHandler
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>
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}.....`);
})