【问题标题】:Struggling to upload my node.js application to azure努力将我的 node.js 应用程序上传到天蓝色
【发布时间】:2020-08-24 19:34:24
【问题描述】:

我是 node.js 的初学者,需要在 Azure 服务器上托管我没有亲自编写的应用程序进行一些测试。该站点在本地托管以及使用 ngrok 托管时运行良好。然而,当我在 azure 上托管它时,我收到以下错误:

[1] 2020-08-23T00:26:36 
Container etuition_0_41152ef3 didn't respond to HTTP pings on port: 8080, failing site start
[2] 2020-08-23T00:26:36 
Container etuition_0_41152ef3 for site etuition did not start within expected time limit.

现在我必须强调,我对 node.js 完全不熟悉,但对我来说,http 请求似乎排列正确。这是我的 index.js 的代码,我认为问题可能出在哪里。

'use strict';

/**
 * Load Twilio configuration from .env config file - the following environment
 * variables should be set:
 * process.env.TWILIO_ACCOUNT_SID
 * process.env.TWILIO_API_KEY
 * process.env.TWILIO_API_SECRET
 */
require('dotenv').load();

const express = require('express');
const http = require('https');
const path = require('path');
const { jwt: { AccessToken } } = require('twilio');

const VideoGrant = AccessToken.VideoGrant;

// Max. period that a Participant is allowed to be in a Room (currently 14400 seconds or 4 hours)
const MAX_ALLOWED_SESSION_DURATION = 14400;

// Create Express webapp.
const app = express();

// Set up the paths for the examples.
[
  'bandwidthconstraints',
  'codecpreferences',
  'dominantspeaker',
  'localvideofilter',
  'localvideosnapshot',
  'mediadevices',
  'networkquality',
  'reconnection',
  'screenshare',
  'localmediacontrols',
  'remotereconnection',
  'datatracks',

].forEach(example => {
  const examplePath = path.join(__dirname, `../examples/${example}/public`);
  app.use(`/${example}`, express.static(examplePath));
});

// Set up the path for the quickstart.
const quickstartPath = path.join(__dirname, '../quickstart/public');
app.use('/quickstart', express.static(quickstartPath));

// Set up the path for the examples page.
const examplesPath = path.join(__dirname, '../examples');
app.use('/examples', express.static(examplesPath));

/**
 * Default to the Quick Start application.
 */
app.get('/', (request, response) => {
  response.redirect('/quickstart');
});



/**
 * Generate an Access Token for a chat application user - it generates a random
 * username for the client requesting a token, and takes a device ID as a query
 * parameter.
 */
app.get('/token', function(request, response) {
  const { identity } = request.query;

  // Create an access token which we will sign and return to the client,
  // containing the grant we just created.
  const token = new AccessToken(
    process.env.TWILIO_ACCOUNT_SID,
    process.env.TWILIO_API_KEY,
    process.env.TWILIO_API_SECRET,
    { ttl: MAX_ALLOWED_SESSION_DURATION }
  );

  // Assign the generated identity to the token.
  token.identity = identity;

  // Grant the access token Twilio Video capabilities.
  const grant = new VideoGrant();
  token.addGrant(grant);

  // Serialize the token to a JWT string.
  response.send(token.toJwt());
});

// Create http server and run it.
const server = http.createServer(app);
const port = process.env.PORT || 8080;
server.listen(port, function() {
  console.log('Express server running on *:' + port);
});

这是我的 package.json


{
  "name": "video-quickstart-js",
  "version": "1.0.0-dev",
  "description": "Twilio Video SDK Quick Start for JavaScript",
  "main": "index.js",
  "scripts": {
    "build": "npm-run-all build:* ",
    "build:examples": "npm-run-all build:examples:*",
    "build:examples:bandwidthconstraints": "copyfiles -f examples/bandwidthconstraints/src/helpers.js examples/bandwidthconstraints/public && browserify examples/bandwidthconstraints/src/index.js > examples/bandwidthconstraints/public/index.js",
    "build:examples:codecpreferences": "copyfiles -f examples/codecpreferences/src/helpers.js examples/codecpreferences/public && browserify examples/codecpreferences/src/index.js > examples/codecpreferences/public/index.js",
    "build:examples:dominantspeaker": "copyfiles -f examples/dominantspeaker/src/helpers.js examples/dominantspeaker/public && browserify examples/dominantspeaker/src/index.js > examples/dominantspeaker/public/index.js",
    "build:examples:localvideofilter": "copyfiles -f examples/localvideofilter/src/helpers.js examples/localvideofilter/public && browserify examples/localvideofilter/src/index.js > examples/localvideofilter/public/index.js",
    "build:examples:localvideosnapshot": "copyfiles -f examples/localvideosnapshot/src/helpers.js examples/localvideosnapshot/public && browserify examples/localvideosnapshot/src/index.js > examples/localvideosnapshot/public/index.js",
    "build:examples:mediadevices": "copyfiles -f examples/mediadevices/src/helpers.js examples/mediadevices/public && browserify examples/mediadevices/src/index.js > examples/mediadevices/public/index.js",
    "build:examples:networkquality": "copyfiles -f examples/networkquality/src/helpers.js examples/networkquality/public && browserify examples/networkquality/src/index.js > examples/networkquality/public/index.js",
    "build:examples:reconnection": "copyfiles -f examples/reconnection/src/helpers.js examples/reconnection/public && browserify examples/reconnection/src/index.js > examples/reconnection/public/index.js",
    "build:examples:screenshare": "copyfiles -f examples/screenshare/src/helpers.js examples/screenshare/public && browserify examples/screenshare/src/index.js > examples/screenshare/public/index.js",
    "build:examples:localmediacontrols": "copyfiles -f examples/localmediacontrols/src/helpers.js examples/localmediacontrols/public && browserify examples/localmediacontrols/src/index.js > examples/localmediacontrols/public/index.js",
    "build:examples:remotereconnection": "copyfiles -f examples/remotereconnection/src/helpers.js examples/remotereconnection/public && browserify examples/remotereconnection/src/index.js > examples/remotereconnection/public/index.js",
    "build:examples:datatracks": "copyfiles -f examples/datatracks/src/helpers.js examples/datatracks/public && browserify examples/datatracks/src/index.js > examples/datatracks/public/index.js",
    "build:quickstart": "browserify quickstart/src/index.js > quickstart/public/index.js",
    "clean": "npm-run-all clean:*",
    "clean:examples": "npm-run-all clean:examples:*",
    "clean:examples:bandwidthconstraints": "rimraf examples/bandwidthconstraints/public/index.js examples/bandwidthconstraints/public/helpers.js",
    "clean:examples:codecpreferences": "rimraf examples/codecpreferences/public/index.js examples/codecpreferences/public/helpers.js",
    "clean:examples:dominantspeaker": "rimraf examples/dominantspeaker/public/index.js examples/dominantspeaker/public/helpers.js",
    "clean:examples:localvideofilter": "rimraf examples/localvideofilter/public/index.js examples/localvideofilter/public/helpers.js",
    "clean:examples:localvideosnapshot": "rimraf examples/localvideosnapshot/public/index.js examples/localvideosnapshot/public/helpers.js",
    "clean:examples:mediadevices": "rimraf examples/mediadevices/public/index.js examples/mediadevices/public/helpers.js",
    "clean:examples:networkquality": "rimraf examples/networkquality/public/index.js examples/networkquality/public/helpers.js",
    "clean:examples:reconnection": "rimraf examples/reconnection/public/index.js examples/reconnection/public/helpers.js",
    "clean:examples:screenshare": "rimraf examples/screenshare/public/index.js examples/screenshare/public/helpers.js",
    "clean:examples:localmediacontrols": "rimraf examples/localmediacontrols/public/index.js examples/localmediacontrols/public/helpers.js",
    "clean:examples:remotereconnection": "rimraf examples/remotereconnection/public/index.js examples/remotereconnection/public/helpers.js",
    "clean:examples:datatracks": "rimraf examples/datatracks/public/index.js examples/datatracks/public/helpers.js",
    "clean:quickstart": "rimraf quickstart/public/index.js",
    "start": "npm run clean && npm run build && node server"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/twilio/video-quickstart-js.git"
  },
  "keywords": [
    "twilio",
    "video",
    "chat",
    "ip",
    "real",
    "time",
    "diggity"
  ],
  "author": "Twilio",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/twilio/video-quickstart-js/issues"
  },
  "homepage": "https://github.com/twilio/video-quickstart-js#readme",
  "dependencies": {
    "dotenv": "^4.0.0",
    "express": "^4.15.2",
    "prismjs": "^1.6.0",
    "stackblur-canvas": "^1.4.0",
    "twilio": "^3.19.1",
    "twilio-video": "^2.7.0"
  },
  "devDependencies": {
    "browserify": "^14.3.0",
    "copyfiles": "^1.2.0",
    "npm-run-all": "^4.0.2",
    "rimraf": "^2.6.1"
  }
}

感谢您的阅读!

【问题讨论】:

  • 您肯定在关注一些文档吗?您是否将容器部署为 Azure Web 应用程序? Something 正在将请求路由到未监听的 8080,我怀疑如果您将它们指向端口 80,它会响应。请参见此处:const port = process.env.PORT || 8080;
  • 从输出日志看来,这段代码从未真正运行过。当调用 npm start 时,所有运行都正确,但似乎比我部署应用程序时 AWS 只运行 npm build,因此 npm 服务器不运行。我添加了 package.json,所以你可以看到这个。
  • "...AWS 只运行 npm build ..."AWS 还是 Azure?您在哪个服务上部署您的应用程序?
  • 抱歉,我最初的帖子是正确的,我使用的是 Azure。我评论的时候肯定有过错。

标签: node.js azure http


【解决方案1】:

首先,确定您使用的是什么服务,AWSAzure Web App Services

无论您使用什么服务,我都建议您使用 git 来部署您的网络应用程序。

  1. Use git to deploy in azure web app services.

  2. Use git to deploy in aws.

您只需确保您的网络应用程序可以在本地成功运行。您使用的端口如app.set('port', process.env.PORT || 3000);const port = process.env.PORT || 3000。这意味着您可以使用 3000 端口在本地成功运行。

更多详情,您可以在另一篇文章中查看我的回答。

  1. Azure - Unhandled Exception: System.IO.FileNotFoundException

  2. Concurrently JS application pipeline install and build hangs (Express js for server, Create-React-App for Client)

您可以参考Action部署web应用时的故障排除方式。希望我的回答能帮到你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-28
    • 2017-07-17
    • 2016-02-02
    • 1970-01-01
    • 2020-04-29
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多