node.jsiisnext.jswindows-servernodejs-server

running Node.js and Next.js application on windows server (IIS)


I have a node.js application (only for api's on port 5000) and a next.js application (for users on port 3000) and I have to run it on windows server, I tried reverse proxy with IIS and I could run it but there is an issue with session and cookies, I believe IIS wont pass the cookie and session correctly to the user or the server and I get a weird UI like showing the login page but also the dashboard, or logging out but still navigation and using the app, I tries these configurations for the apps:
API (node.js) web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="api" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:5000/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Website (next.js) web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="web" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:3000/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

and this is the IIS sites: IIS sites


Solution

  • I believe the problem had something with IIS memory cashing duration, so I changed it from 60 to 1 and it fixed the problem, still I believe there could be a better solution but that is what I did for now.

    these are the steps to do it:

    1. in IIS select the server (probably named after you computer/server name).
    2. go to Application Request Routing Cache page.
    3. go to Server Proxy Settings via right side panel.
    4. from Cache Sttings change Memory cache duration (seconds) to 1