How to host a service and static content in iisnode

I have my courier website. But now I need to host it on IIS. How can I get my routing to work with IISNode?

I managed to move my static content to / public folder (html, front js, etc.). I did not want to do this, but I got this part.

I transferred server logic to server / server.

Earlier, I had the usual routing .Net Web API, where my services were located in / api. I moved them to / server / api.

Whenever I try to request my API, I get 404. How can I get this working with IISNode?

app.use("/api", require("./api")); // routes/api/index.js var router = require('express').Router(); router.use('/questionsets', require('./questionsets')); module.exports = router; var router = require('express').Router(); router.use('/questionsets', require('./questionsets.js')); module.exports = router; // routes/api/questions.js var router = require('express').Router(); router.get('/', function (req, res) { ... }); router.get('/:id', function (req, res) { ... }); module.exports = router; <?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <security> <requestFiltering> <hiddenSegments> <remove segment="bin" /> </hiddenSegments> </requestFiltering> </security> <handlers> <add name="iisnode" path="bin/www" verb="*" modules="iisnode" /> </handlers> <iisnode loggingEnabled="false" /> <httpErrors errorMode="Detailed" existingResponse="Replace"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="/" responseMode="ExecuteURL" /> </httpErrors> <rewrite> <rules> <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true"> <match url="iisnode" /> </rule> <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"> <match url="^bin\/www\/debug[\/]?" /> </rule> <rule name="StaticContent" patternSyntax="ECMAScript" stopProcessing="true"> <match url=".*" /> <action type="Rewrite" url="{C:1}" logRewrittenUrl="true" /> <conditions> <add input="{REQUEST_URI}" pattern=".*?\/(.*)" /> </conditions> </rule> <rule name="DynamicContent" patternSyntax="ECMAScript"> <match url=".*" /> <conditions> <add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True" /> </conditions> <action type="Rewrite" url="server/app.js" logRewrittenUrl="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration> 

Source for setting URL rewriting

+5
source share
1 answer

You need to set up application request routing here , and the documentation.

Just placing your files on the server side under the server will not work. Start your express server by, say, listening to http: // localhost: 3200 / , requesting the route "/" to "localhost: 3200" will simply route each request to your express server.

0
source

Source: https://habr.com/ru/post/1259072/


All Articles