私はGitHubでホストされているnode.jsアプリケーションをAzureでホストしようとしています。私はまだ失敗した最小限の例にしました。GitHubでホストされているnode.jsアプリケーションをAzureで正しく実行するには
これは私の./server/index.js
ファイルです:
var http = require('http');
var server = http.createServer(function (request, response){
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello world!\n");
});
server.listen(80);
console.log("Server running at http://127.0.0.1:80/");
そして、これは私のpackage.json
ファイルです:
{
"name": "testapp",
"version": "1.0.0",
"description": "",
"main": "./server/index.js",
"scripts": {
"start": "node ./server/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
自分のアプリケーションのすべてのファイルです。 localhostでnpm start
を起動するとうまく動作し、 "Hello world!"期待どおりの応答。
次に、GitHub
のレポを作成し、このアプリケーションをGitHub
にプッシュし、両方のファイルが存在することを確認しました。
次に、私はAzureにWeb app
を作成し、このGitHub
リポジトリからデプロイするように設定しました。ビルドはうまくいったようです。これはGenerating Deployment Script
から出力されます:
Using cached version of deployment script (command: 'azure -y --no-dot- deployment -r "D:\home\site\repository" -o "D:\home\site\deployments\tools" --node --sitePath "D:\home\site\repository"').
そして、これはRunning Deployment Command
の出力です:
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling node.js deployment.
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
Copying file: 'server\index.js'
Using start-up script server/index.js from package.json.
Generated web.config.
The package.json file does not specify node.js engine version constraints.
The node.js application will run with the default node.js version 4.2.3.
Selected npm version 3.5.1
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
Finished successfully.
そしてAzureがdelpoyment成功したと言います。
しかし、appname.azurewebsites.net
に移動すると、Status Code
が500
と応答し、応答データがまったくありません。
これが期待どおりに動作するには、ここでは欠けているパズルの部分は何ですか?アプリはAzureの上で実行されている場合、それはアズールによって割り当てられたポートを使用します
process.env.PORT = process.env.PORT || 80;
server.listen(process.env.PORT);
:あなたはこのような何かを行うことができますので
「80」はアズールが世界に公開する予定のポートですか? – jonrsharpe
これはdafault httpポートなので '80'を使用しましたが、特に何も設定していません。これはどこで設定できますか?私はAzureポータル内でこれの設定を見つけることができません。 –