-
-
Save Junch/0f218f8aef44e34727b0 to your computer and use it in GitHub Desktop.
Cut off IIS virtual path (base url) from the request url when running with IISNODE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Cut off IIS virtual path (base url) from the request url when running via IISNODE | |
| // with URL Rewrite | |
| // | |
| // Add "APPL_MD_PATH" to "promoteServerVars" iisnode attribute in web.config | |
| var iisNodeBaseUrl = function () { | |
| return function (req, res, next) { | |
| var appMdPath = req.headers['x-iisnode-appl_md_path']; | |
| if (appMdPath) { | |
| var rootPos = appMdPath.search("/ROOT"); | |
| if (rootPos > -1) { | |
| // e.g. '/LM/W3SVC/1/ROOT/testbaseurl' -> '/testbaseurl' | |
| var baseUrl = appMdPath.slice(appMdPath.search("/ROOT") + ("/ROOT").length); | |
| if (baseUrl <> "") { | |
| // e.g. '/testbaseurl/assets/js/script.js' -> '/assets/js/script.js' | |
| req.url = req.url.replace(baseUrl, ""); | |
| } | |
| } | |
| } | |
| return next(); | |
| }; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <configuration> | |
| <system.webServer> | |
| <handlers> | |
| <add name="iisnode" path="index.js" verb="*" modules="iisnode" /> | |
| </handlers> | |
| <iisnode promoteServerVars="APPL_MD_PATH" /> | |
| <rewrite> | |
| <rules> | |
| <rule name="server"> | |
| <match url="/*" /> | |
| <action type="Rewrite" url="index.js" /> | |
| </rule> | |
| </rules> | |
| </rewrite> | |
| </system.webServer> | |
| </configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment