我正在使用Node尝试Azure并使用Wercker CI构建,然后通过FTP部署到Azure。
但似乎我在使用它时遇到了一些麻烦。我正在复制server.js
文件以及package.json
和其他一些资产。但它似乎没有运行npm install
命令。另外,我到达网站时得到You do not have permission to view this directory or page.
。
有一个web.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>
server.js
就像:
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
最后,package.json
包含必要的代码。
所以我只是想知道,有没有办法将应用程序部署到Azure并触发npm install
并启动Web服务器?
我可以看到,如果你通过Git进行部署,Kudu会为我做所有这些。但是我不认为在使用Wercker进行部署时这是我的选择。另外,我在CI构建期间编译了一些TypeScript文件,我不希望那些版本控制,所以我需要存储所有编译文件的git repo也不是一个选项。
我真的很感激如何处理这个问题。
答案 0 :(得分:2)
通过FTP npm install
部署时,将不会自动运行。在这种情况下,您可以使用控制台运行for (var y in data) {
if (typeof(uniqueYears[data[y].year]) === "undefined") {
distinctYears.push(data[y].year);
year = data[y].year;
if (year === "" || year === null) {
year = "";
}
strResult += "<th style='text-align:left;'><h2>" + year + "</h2></th>";
//console.log(year);
uniqueYears[data[y].year] = 0;
}
}
答案 1 :(得分:1)
根据你的描述,它有点困惑:
所以我只是想知道,有没有办法将应用程序部署到Azure并触发npm安装并启动Web服务器?
我可以看到,如果你通过Git进行部署,Kudu会为我做所有这些。但我认为这不是我的选择
通常,通过Git将您的节点应用程序部署到Azure,它将自动运行npm install。如果您不想使用Git,您更喜欢哪些具体要求。
目前我无法重现您关于Wercker的问题。通过GIT部署时是否会出现错误?
根据您对@ theadriangreen的评论,由于时间过长,您似乎在npm install
失败了。如果是这样,您可以尝试启用Web应用程序的“始终开启”设置,以防止您的网站在一段时间内没有收到任何请求时卸载。
此外,如果在部署后仍需要一些自定义任务,则可以参考Post Deployment Action Hooks来配置自定义部署脚本。
答案 2 :(得分:0)
通过FTP npm install
部署时,将不会自动运行。在这种情况下,您将必须在所部署的文件夹中包含所有依赖项。所以你可以这样做并通过FTP部署,或者你可以使用git。
如果您使用git,您可以将不想部署的文件添加到.gitignore,然后单独部署它们(即将它们放在blob中)。