-
Notifications
You must be signed in to change notification settings - Fork 18
Description
When hosting node applications behind IIS using IISNode or HTTPPlatformHandler IIS passes the port to listen to as an environment variable. In order for origo-server to work it must then bind to the provided port, not the default 3000.
The solution is simply binding to port process.env.PORT || 3000. This is a common pattern even if not hosting in IIS. As a side node HTTPPlatformHandler uses HTTP_PLATFORM_PORT but that can be remapped in web.config to avoid adding too much confusion to app.js.
Also when hosting in IIS it is common to host as an sub-application under a site in order to share binding address and port with other applications to avoid CORS-problems and share cookies. In that case the express application must set up its route bindings including the virtual path as the express app will receive the complete path. To seamlessly support both hosting as a sub-application and as a site the virtual path could be passed as an environment variable that that is always prepended to all routes. If the application is hosted as a site or by any other environment than IIS it will be empty and if the application is hosted at a virtual path the calling process (which is likely to know the virtual path) sets it as an environment variable. For IISNode and HTTPPlatformHandler it is set in web.config.
// Do this once
var virtualPath = process.env.virtualPath || '';
// Do this for all routes
app.use(virtualPath + '/domain', domainRouter);