0

I am using IISNode to server Node.js files over IIS on Windows Azure. But when I try to access the server path using http://127.0.0.1/mysite/node/ its throwing the following error

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP reason: Internal Server Error

And in the log file generated in iisnode folder it shows the following error:

Application has thrown an uncaught exception and is terminated:
Error: Cannot find module 'D:\Project\Files\mysite\node"'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (C:\Program Files\iisnode\interceptor.js:210:1)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

But when I try this path http://127.0.0.1/mysite/node/app.js it executes the app.js file. However, I do not want to reveal the app.js file name in the URL. Can I set this file as the default file or startup file when I use this path http://127.0.0.1/mysite/node/?


UPDATE

Further to my answer below:

    <rule name="DynamicContent">
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
      </conditions>
      <action type="Rewrite" url="node/main.js"/>
    </rule>

This block of code in config is preventing calls to any .net files instead it is redirecting to node for execution. How can i redirect to node only when the URL contains /node/ at the end like http://127.0.0.1/mysite/node/?

2 Answers 2

1

I think this solution works.

Evaluating now...


UPDATE

    <rule name="DynamicContent">
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
      </conditions>
      <action type="Rewrite" url="node/main.js"/>
    </rule>

This block of code in config is preventing calls to any .net files and it is redirecting to node for execution.

How can i redirect to node only when the URL contains /node/ at the end like http://127.0.0.1/mysite/node/?

Sign up to request clarification or add additional context in comments.

Comments

0

We can leverage location element in web.config file as deciding that all files in a particular directory are supposed to be treated as node.js applications.

Here is my sites directory figure in iis:

enter image description here

And here is the content of web.config: <configuration> <location path="node"> <system.webServer> <handlers> <add name="iisnode" path="*.js" verb="*" modules="iisnode" /> </handlers>
</system.webServer> </location> </configuration>

And the URL likehttp://localhost /mysite/node will handled by iisnode as configured in web.config.

And the others will not be effected by iisnode, for example in this test, http://localhost /mysite/php/index.php still run PHP script.

For more infomation, we can see in Hosting node.js applications in IIS on Windows

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.