tjanczuk / iisnode

Hosting node.js applications in IIS on Windows
Other
1.86k stars 588 forks source link

iisnode and sails.js #298

Open gisjeremy opened 11 years ago

gisjeremy commented 11 years ago

Can you point me in the right direction for getting a sails.js project running under iisnode?

I don't think that there will need to be any url rewriting as the url requests are all handled by the node.js server running sails.js mvc framework, but I may be wrong.

As of now I have a web.config that looks like this

``` ```

when I hit the url /node/folder/app.js I get a 404 from my sails app which means it's running but not handling the request. All routes are handled in a routes.js file under a config folder in the main project.

Thanks,

Jeremy

davepreston commented 11 years ago

@gisjeremy, you figure this out yet? I was hoping to do the same thing (sailsjs & iisnode). Currently have the same symptoms (404 page).

I'm not sure if there's a way in iisnode to get the output of what would normally be on the console. That would be particularly helpful in troubleshooting.

--Dave

gisjeremy commented 11 years ago

Sort of...I will send you the web.config file I used tomorrow. I ended up serving assets from the assets folder instead of .tmp/public and had to preface all urls with the alias that I set in iis. This also involved changing any urls to images, scripts and styles as well as not injecting anything using the layout but rather setting the urls that I wanted as static in the layout.ejs (you can still serve from assets/linker, but if you inject sails copies to .tmp/public/linker), so just remove the injection tags.

There is probably an easier way but I was under the gun to get it working, so that's what I have for now. Altering the grunt file gave me some success but I didn't have time to complete it.

On Thursday, October 10, 2013, Dave Preston wrote:

@gisjeremy https://github.com/gisjeremy, you figure this out yet? I was hoping to do the same thing (sailsjs & iisnode). Currently have the same symptoms (404 page).

I'm not sure if there's a way in iisnode to get the output of what would normally be on the console. That would be particularly helpful in troubleshooting.

--Dave

— Reply to this email directly or view it on GitHubhttps://github.com/tjanczuk/iisnode/issues/298#issuecomment-26101511 .

gisjeremy commented 11 years ago

Hi Dave -

I appologize, I forgot to send the web.config over. I will do so as soon as I can jump back onto my work computer.

On Thursday, October 10, 2013, Dave Preston notifications@github.com wrote:

@gisjeremy, you figure this out yet? I was hoping to do the same thing (sailsjs & iisnode). Currently have the same symptoms (404 page).

I'm not sure if there's a way in iisnode to get the output of what would normally be on the console. That would be particularly helpful in troubleshooting.

--Dave

— Reply to this email directly or view it on GitHub.

gisjeremy commented 11 years ago

web.config...

<?xml version="1.0" encoding="utf-8"?>

On Sat, Oct 12, 2013 at 10:15 AM, Jeremy Hazel jeremyrhazel@gmail.comwrote:

Hi Dave -

I appologize, I forgot to send the web.config over. I will do so as soon as I can jump back onto my work computer.

On Thursday, October 10, 2013, Dave Preston notifications@github.com wrote:

@gisjeremy, you figure this out yet? I was hoping to do the same thing (sailsjs & iisnode). Currently have the same symptoms (404 page).

I'm not sure if there's a way in iisnode to get the output of what would normally be on the console. That would be particularly helpful in troubleshooting.

--Dave

— Reply to this email directly or view it on GitHub.

davepreston commented 11 years ago

Thanks @gisjeremy I hadn't figured out the rules yet to get debug and logging to work so these should be helpful.

Did you have to do anything in sails to modify your routes based on iisnode? Sails isn't expecting the full path, just the portion of the path AFTER the service root. But iisnode is passing on the full path. I have iis set up to have an application called service. That's where I'm putting my web.config with all the rewriting, etc. So my urls are like: http://localhost/service/users http://localhost/service/users/1234

So far, in order to get sails to recognize these routes I'm having to customize which means the blueprints won't work. (plus it's just uglier :))

/service/users (instead of /users) /service/users/:user_id (instead of /users/:user_id)

Any thoughts? or are you just mapping your entire iis server root to sails?

--Dave

gisjeremy commented 11 years ago

Unfortunately I am currently mapping iis to sails. There has got to be a better way but I haven't made it that far yet.

Also don't forget to make sure to disable the iisnode and rewrite modules on your default website and only enable them on your specific node app if you are running iisnode alongside other traditional apps. If you do not every application under the default website will look for a web.config in order to rewrite and then throw an error when it doesn't find one.

On Wednesday, October 16, 2013, Dave Preston wrote:

Thanks @gisjeremy https://github.com/gisjeremy I hadn't figured out the rules yet to get debug and logging to work so these should be helpful.

Did you have to do anything in sails to modify your routes based on iisnode? Sails isn't expecting the full path, just the portion of the path AFTER the service root. But iisnode is passing on the full path. I have iis set up to have an application called service. That's where I'm putting my web.config with all the rewriting, etc. So my urls are like: http://localhost/service/users http://localhost/service/users/1234

So far, in order to get sails to recognize these routes I'm having to customize which means the blueprints won't work. (plus it's just uglier :))

/service/users (instead of /users) /service/users/:user_id (instead of /users/:user_id)

Any thoughts? or are you just mapping your entire iis server root to sails?

--Dave

— Reply to this email directly or view it on GitHubhttps://github.com/tjanczuk/iisnode/issues/298#issuecomment-26428025 .

davepreston commented 11 years ago

Thanks for the tips. I did find a workable solution (although I would prefer an option in iisnode to send relative paths instead). There is a prefix option in the config/controllers.js file. It impacts all the routes for the blueprints. So I was able to modify it as:

module.exports.controllers = {
  blueprints: {
    // Optional mount path prefix for blueprints
    // (the automatically bound routes in your controllers)
    // e.g. '/api/v2'
    prefix: '/service',

Unfortunately, I still have to modify all my custom routes to look like '/service/controller' instead of just '/controller'. It's uglier, but at least the blueprints work without modification.

knownasilya commented 10 years ago

Has anyone gotten a good solution that doesn't involve changing Sails code?

knownasilya commented 10 years ago

I haven't been able to get Sails working, since process.env.PORT is a named pipe, it errors out..

debug: --------------------------------------------------------
debug: :: Thu Jan 02 2014 09:21:32 GMT-0500 (Eastern Standard Time)
debug: 
debug: Environment    : "production"
debug: Port       : \\.\pipe\ad0c329a-28f0-496f-b299-5aecf254d4cf
debug: --------------------------------------------------------
error: Server doesn't seem to be starting.
error: Perhaps something else is already running on port \\.\pipe\ad0c329a-28f0-496f-b299-5aecf254d4cf?
error: Grunt ::     Warning: Running "less:dev" (less) task Use --force to continue.
 Running "less:dev" (less) task Use --force to continue.

This is where sails starts express and where the port is set.

davepreston commented 10 years ago

Are you sure that's the problem? I have seen that error on multiple occasions even though it still started up. It was as if iisnode was starting it twice simultaneously. I'm going off a vague memory though, so I can't be sure.

Can you see the node process running in the task manager? I presume you tried hitting your iis server and got no response?

But to answer your previous question, yes, sails runs in iisnode with no modifications. I've been doing service development lately, so I haven't been running inside iisnode in the last month or so. (I find the command-line to be easier to troubleshoot than the iisnode logs).

knownasilya commented 10 years ago

Yeah @davepreston, I'm glad I don't have to run node in iisnode during dev (setting up the project on an alpha server is my issue here).

I set sails logging to verbose and in the stdout iisnode logs it goes as far as the first grunt console log and doesn't output anything, and the stderr log just gives me the "something is already running" error.

I don't see node running in processes or services.. Looks like some grunt errors possibly, but the log is cut off.. so I have no idea..

edit: I enabled some more logging, and it looks like an issue with the node async lib?..

Application has thrown an uncaught exception and is terminated:
TypeError: Cannot call method 'on' of null
    at load (D:\hosting\websites\node\ctbb\node_modules\sails\lib\grunt\index.js:35:16)
    at Array.loadGrunt [as 1] (D:\hosting\websites\node\ctbb\node_modules\sails\lib\app\load.js:235:3)
    at listener (D:\hosting\websites\node\ctbb\node_modules\sails\node_modules\async\lib\async.js:462:46)
    at D:\hosting\websites\node\ctbb\node_modules\sails\node_modules\async\lib\async.js:416:17
    at Array.forEach (native)
    at _each (D:\hosting\websites\node\ctbb\node_modules\sails\node_modules\async\lib\async.js:32:24)
    at Object.taskComplete (D:\hosting\websites\node\ctbb\node_modules\sails\node_modules\async\lib\async.js:415:13)
    at processImmediate [as _immediateCallback] (timers.js:330:15)

Line 35 is here

knownasilya commented 10 years ago

@tjanczuk I'm having issues with iisnode not returning errors. At one point I set loggingEnabled to false and visited domain/app/app.js/debug and got a 500 error with details, but now I only get 404s even though the same thing is still going on. By the way, the node-inspector isn't enabling when visiting that url..

knownasilya commented 10 years ago

I've upgraded to 0.10 alpha of Sails, and now I get no messages, but still have a 404. The logs say the server started. Here is my web.config.

<configuration>
  <system.webServer>

    <handlers>
      <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
    </handlers>

    <rewrite>
      <rules>
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
          <match url="^app.js\/debug[\/]?" /> 
        </rule>       

        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="app.js" logRewrittenUrl="true"/>
          <match url="/*"/>      
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
jybleau commented 10 years ago

Hello, did someone figured it out yet? I'm not sure how to apply @davepreston 's solution. I'm stuck at the 404 page...

jybleau commented 10 years ago

Figured it out... I used @knownasilya web.config My sails app is under a subfolder, example: node.mydomain.com/sails As @davepreston pointed out, I edited the controller.js prefix to prefix: '/sails', To get the default home page showing up, I edited the default route in route.js to '/sails' instead of only '/' Example:

// (This would also work if you had a file at: `/views/home.ejs`)
  '/sails': {
    view: 'home/index'
  }

Also: I first installed the sails package globally npm -g install sails but my test app could not find it when loaded by iisnode; probably a PATH problem. Anyway, I just installed the sails package into my test app folder and it worked.

mnaughto commented 9 years ago

So I've had SailsJS (0.10.x) working pretty solidly with iisnode for a while now. (Though, admittedly, I'm here to post about a very odd situation...)

Some tips:

That's all I can think of at the moment.

tjwebb commented 9 years ago

Are you interested in posting a writeup or module that helps other sails.js users run iisnode? We love to give shoutouts to community projects. Let me know, thanks.

-- the sails.js team

jybleau commented 9 years ago

If my next Sails app is deployed using iisnode, I will contact you back if no one has wrote an How-to yet at that moment. Thanks for asking.

bartam commented 9 years ago

Has anyone made progress on this? I can run an express app on IIS without a problem, but Sails returns a 500 error:

To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.
To do that, run `npm install sails`

Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.
When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,
but if it doesn't, the app will run with the global sails instead!

I can run "node app.js" and the server runs. I've install sails locally and verified that the iis process is running in the project folder. Even adding absolute paths to the modules don't work.

jybleau commented 9 years ago

Sorry, I did not use Sails on IIS. Can't find anything useful about it on stackoverflow too.

Another way of serving any Node app from IIS would be to run it standalone and setup a reverse proxy in IIS.

bartam commented 9 years ago

The only issue I've had with port forwarding to the sails app is using Windows Auth. In IISnode, it's pretty straightforward and I'm not sure it's even possible without IISnode.