Azure: запуск NodeJS в WebApp

Автор: | 07/06/2017
 

Задача: запустить NodeJS приложение в Azure WebApp.

Для запуска NodeJS приложений в IISAzure использует iisnode.

Касаемо портов:

Your Node site is actually given a Named Pipe which receives the incoming requests, not a TCP port like you would use when running locally or hosting yourself. Even if you could open a TCP port, Azure Websites are really only meant for traditional websites and don’t have a way to open ports to the outside world.

Процесс запуска приложения простой до неприличия.

Берём тестовое приложение от Azure:

[simterm]

$ git clone https://github.com/Azure-Samples/nodejs-docs-hello-world
$ cd nodejs-docs-hello-world/

[/simterm]

Запускаем:

[simterm]

$ npm start

> [email protected] start /tmp/nodejs-docs-hello-world
> node index.js

Server running at http://localhost:1337

[/simterm]

С другой консоли проверяем:

[simterm]

$ curl http://localhost:1337
Hello Azure!

[/simterm]

Создаём WebApp, и копируем туда приложение.

Создание и работа с Azure App Service описано тут>>> и тут>>>.

Настраиваем git-деплой>>>, деплоим:

[simterm]

$ git clone https://[email protected]:443/nodetest12312.git
Cloning into 'nodetest12312'...
Password for 'https://[email protected]:443': 
warning: You appear to have cloned an empty repository.
$ cp -r nodejs-docs-hello-world/* nodetest12312/
$ cd nodetest12312/
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        LICENSE
        README.md
        index.js
        package.json
        process.json

nothing added to commit but untracked files present (use "git add" to track)
$ git add -A && git commit -m "init deploy" && git push
[master (root-commit) 47a8282] init deploy
 5 files changed, 68 insertions(+)
 create mode 100644 LICENSE
 create mode 100644 README.md
 create mode 100644 index.js
 create mode 100644 package.json
 create mode 100644 process.json
Password for 'https://[email protected]:443': 
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.87 KiB | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)
remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id '47a82825f4'.
remote: Generating deployment script.
remote: Generating deployment script for node.js Web Site
remote: Generated deployment script files
remote: Running deployment command...
remote: Handling node.js deployment.
remote: KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
remote: Deleting file: 'hostingstart.html'
remote: Copying file: 'index.js'
remote: Copying file: 'LICENSE'
remote: Copying file: 'package.json'
remote: Copying file: 'process.json'
remote: Copying file: 'README.md'
remote: Using start-up script index.js from package.json.
remote: Generated web.config.
remote: Node.js versions available on the platform are: 0.6.20, 0.8.2, 0.8.19, 0.8.26, 0.8.27, 0.8.28, 0.10.5, 0.10.18, 0.10.21, 0.10.24, 0.10.26, 0.10.28, 0.10.29, 0.10.31, 0.10.32, 0.10.40, 0.12.0, 0.12.2, 0.12.3, 0.12.6, 4.0.0, 4.1.0, 4.1.2, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.3.0, 4.3.2, 4.4.0, 4.4.1, 4.4.6, 4.4.7, 4.5.0, 4.6.0, 4.6.1, 5.0.0, 5.1.1, 5.3.0, 5.4.0, 5.5.0, 5.6.0, 5.7.0, 5.7.1, 5.8.0, 5.9.1, 6.0.0, 6.1.0, 6.2.2, 6.3.0, 6.5.0, 6.6.0, 6.7.0, 6.9.0, 6.9.1, 6.9.2, 6.9.4, 6.9.5, 6.10.0, 7.0.0, 7.1.0, 7.2.0, 7.3.0, 7.4.0, 7.5.0, 7.6.0, 7.7.4, 7.10.0.
remote: Selected node.js version 7.10.0. Use package.json file to choose a different version.
remote: Selected npm version 4.2.0
remote: Updating iisnode.yml at D:\home\site\wwwroot\iisnode.yml
remote: ............
remote: npm WARN lifecycle The node binary used for scripts is D:\Program Files (x86)\nodejs\6.9.1\node.exe but npm is using D:\Program Files (x86)\nodejs\7.10.0\node.exe itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
remote: Finished successfully.
remote: Running post deployment command(s)...
remote: Deployment successful.
To https://nodetest12312.scm.azurewebsites.net:443/nodetest12312.git
 * [new branch]      master -> master

[/simterm]

Проверяем приложение в WebApp:

[simterm]

$ curl http://nodetest12312.azurewebsites.net
Hello Azure!

[/simterm]

Готово.