3
votes

I am trying out Azure with Node and using Wercker CI to build then deploy to Azure via FTP.

But it seems like I am having some trouble getting this to work. I am copying a server.js file along with a package.json and some other assets. But it looks like nothing runs the npm install command. Plus, I get a You do not have permission to view this directory or page. when reaching the site.

There is a web.config file with the following config:

<!--
    This configuration file is required if iisnode is used to run node processes behind IIS or IIS Express.  For more information, visit:
    https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
    <system.webServer>
        <handlers>
            <!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
            <add name="iisnode" path="./server.js" verb="*" modules="iisnode"/>
        </handlers>
        <rewrite>
            <rules>
                <!-- Don't interfere with requests for logs -->
                <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
                        <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$"/>
                </rule>
                <!-- Don't interfere with requests for node-inspector debugging -->
                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                    <match url="^\.\/server.js\/debug[\/]?" />
                </rule>
                <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
                <!--<rule name="StaticContent">
                    <action type="Rewrite" url="./app/assets/{REQUEST_URI}"/>
                </rule>-->
                <!-- All other URLs are mapped to the Node.js application entry point -->
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                    </conditions>
                    <action type="Rewrite" url="./server.js"/>
                </rule>
            </rules>
        </rewrite>
        <iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade;middleware\*.js"/>
    </system.webServer>
</configuration>

And the server.js is as simple as:

var http_1 = require('http');
var express = require('express');
var log4js_1 = require('log4js');
var morgan = require('morgan');
var split = require('split2');
// NOTE: Some of the features used are only available in ES6
// do not forget to start the server using `node --harmony` option so that everything will work properly,
// in case you use anything that is behind the staging flag.
// Check https://nodejs.org/en/docs/es6/#which-features-are-behind-the-es_staging-flag
// to see which features require the flag.
var app = express();
var APP_PORT = process.env.PORT || 5000;
var APP_PATH = __dirname + "/public";
// We will need to split the output from morgan into lines to avoid trailing line feeds,
// https://github.com/expressjs/morgan/issues/70.
var log = log4js_1.getLogger();
var log4jsStream = split().on('data', function (line) {
    log.debug(line);
});
app.use(morgan('tiny', { stream: log4jsStream }));
// `__dirname` in this case will be `./dist/` since we start the server from there.
app.use(express.static(APP_PATH));
app.all('/*', function (req, res) {
    res.sendFile(APP_PATH + "/index.html");
});
var server = http_1.createServer(app);
server.listen(APP_PORT, function () {
    // console.log(`Express server listening on port ${APP_PORT}`);
});

//# sourceMappingURL=server.js.map

Finally, the package.json contains the necessary deps.

So I am just wondering, is there any way to deploy an app to Azure and trigger the npm install and start the web server?

I can see that if you do the deployment via Git, Kudu will do all of that for me. But I do not think that is an option for me while using Wercker to do the deployment. Also, I am compiling some TypeScript files during the CI builds and I do not want those in version control, so having a git repo where I need to store all the compiled files is also not an option.

I would really appreciate some input on how to handle this.

3

3 Answers

3
votes

When deploying via FTP npm install will not be automatically run. In this case you can use console to run npm install

2
votes

It’s a little confused according your description:

So I am just wondering, is there any way to deploy an app to Azure and trigger the npm install and start the web server?

I can see that if you do the deployment via Git, Kudu will do all of that for me. But I do not think that is an option for me

Generally, via Git to deploy your node app to Azure, it will run npm install automatically. What are specific requirements you prefer to if you wouldn’t like to use Git.

Currently I can’t reproduce your issue about Wercker. Does it occur errors when you deploy via GIT?

And according your comments with @ theadriangreen, it seems you failed in npm install because of time out. If so, you can try to enable Always On setting of your Web App to prevent your site unload if they haven’t gotten any requests for a period time.

Additionally, if you still need some custom tasks after deployment, you can refer to Post Deployment Action Hooks to configure your custom deployment scripts.

1
votes

When deploying via FTP npm install will not be automatically run. In this case you're going to have to include all of the dependencies in the folder that you deploy. So you can do that and deploy over FTP, or you can use git.

If you use git, you can add the files that you don't want deployed to your .gitignore, and then deploy them separately (i.e. put them in a blob).