0

I am hosting an express server with IIS Node. If I create a brand new site in IIS I can see the express server at the following url: email.local; however if I try to add that same exact server as an application inside of the site that hosts my front end I am not able to run the server or send postman requests to it. Postman responds with a 404 error when sending an api request over https and a 403 error when sending the request over http. and my browser just shows the following: "can not GET /api/"

To be clear I want to be able to interact with this server when I navigate to www.mysite.com/api

Here is my webpack config file:

<configuration>
<system.webServer>
    <handlers>
        <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
    </handlers>
    <rewrite>
        <rules>
            <rule name="sendToNode">
                <match url="/*" />
                <action type="Rewrite" url="server.js" />
            </rule>
        </rules>
        <outboundRules>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
</system.webServer>
Alex Motor
  • 59
  • 8
  • Use search engines to learn how to use browser developer tools to analyze CORS issues, since likely that you hit such. Front end application frameworks usually have their own ways to resolve CORS issues, which you can learn further on. – Lex Li Feb 07 '23 at 19:14
  • Really what I am looking for is a way to link that express server to the actual website. So that I can go to www.mysite.com/api and see the express server. Also as it sits now. When I make a request on the website it fails with the status {blocked: mixed-content} – Alex Motor Feb 07 '23 at 21:53
  • You should avoid hosting Node.js web apps on Windows, as Linux is preferred. But if you insist, HttpPlatformHandler is there, https://halfblood.pro/running-nodejs-web-apps-on-iis-with-httpplatformhandler/ – Lex Li Feb 08 '23 at 02:12
  • The answer of [this question](https://stackoverflow.com/questions/47332793/use-node-js-express-on-iis-with-iisnode) may be useful to you. – TengFeiXie Feb 08 '23 at 09:48
  • Thank you for the links. I am able to get the server running successfully through IISNode if I create a completely new site in IIS. The problem is that it is bound to a local url (email.local) and since there is no SSL cert I can only connect via HTTP and not HTTPS. This throws the following error when trying to send a POST request from my front end {blocked: mixed-content}. So the solution to this is to add the server as an additional application for the site that hosts the front end. However doing this and selecting the SAME folder as the standalone node "site" throws the 403 error. – Alex Motor Feb 08 '23 at 16:13
  • I just gave up on this and ended up using PM2 and adding the express server as a reverse proxy. This ended up working perfectly. – Alex Motor Feb 08 '23 at 21:54

0 Answers0