Created
May 4, 2012 22:55
-
-
Save tjanczuk/2598211 to your computer and use it in GitHub Desktop.
iisnode interceptor
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
(function () { | |
// refactor process.argv to determine the app entry point and remove the interceptor | |
var appFile; | |
var newArgs = []; | |
process.argv.forEach(function (item, index) { | |
if (index === 2) | |
appFile = item; | |
if (index !== 1) | |
newArgs.push(item); | |
}); | |
process.argv = newArgs; | |
// intercept console.log to convert strings to uppercase | |
var oldLog = console.log; | |
console.log = function (thing) { | |
if (typeof thing === 'string') | |
oldLog(thing.toUpperCase()); | |
else | |
oldLog.apply(this, arguments); | |
}; | |
// run the original application entry point | |
require(appFile); | |
})(); |
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
nodeProcessCommandLine: "c:\program files (x86)\nodejs\node.exe" "c:\program files\iisnode\www\helloworld\interceptor.js" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The interceptor should overwrite require.main.filename to point to the one that is expected. It is used to figure out what module kicked off a process. In a web app, it is often used to find the root of the website.