Azure上的NodeJ - 站点无法加载

时间:2018-05-03 23:21:47

标签: node.js azure azure-web-sites

我在Azure上有一个非常简单的expressJs应用程序,自3月以来一切正常......

今天我去了网站,发现了一个" Service Unavailable"作为输出...在重新发布网站后,我在日志中得到了许多奇怪的错误,完全没有意义:

https://<my app name>.scm.azurewebsites.net/api/logstream

检索下面的

日志

2018-05-03T23:11:48  Updating branch 'master'.
2018-05-03T23:11:52  Updating submodules.
2018-05-03T23:11:52  Preparing deployment for commit id '7579046ef3'.
2018-05-03T23:11:56  Generating deployment script.
2018-05-03T23:11:56    Using cached version of deployment script (command: 'azure -y --no-dot-deployment -r "/home/site/repository" -o "/home/site/deployments/tools" --node --sitePath "/home/site/repository"').
2018-05-03T23:11:56  Running deployment command...
2018-05-03T23:11:56    Command: "/home/site/deployments/tools/deploy.sh"
2018-05-03T23:11:59    Handling node.js deployment.
2018-05-03T23:11:59    Kudu sync from: '/home/site/repository' to: '/home/site/wwwroot'
2018-05-03T23:11:59    Copying file: '.editorconfig'
2018-05-03T23:11:59    Copying file: '.eslintrc.js'
2018-05-03T23:11:59    Copying file: '.gitignore'
2018-05-03T23:11:59    Copying file: 'Procfile'
2018-05-03T23:12:00    Copying file: 'bitbucket-pipelines.yml'
2018-05-03T23:12:00    Copying file: 'package-lock.json'
2018-05-03T23:12:00    Copying file: 'package.json'
2018-05-03T23:12:00    Copying file: 'readme.md'
2018-05-03T23:12:00    Ignoring: .git
2018-05-03T23:12:00    Copying file: '.vscode/launch.json'
2018-05-03T23:12:00    Copying file: 'public/favicon.ico'
2018-05-03T23:12:00    Copying file: 'public/swagger.html'
2018-05-03T23:12:00    Copying file: 'public/swagger.json'
2018-05-03T23:12:00    Copying file: 'public/swagger.yaml'
2018-05-03T23:12:00    Copying file: 'server/server.js'
2018-05-03T23:12:00    Copying file: 'server/models/dtlCall.js'
2018-05-03T23:12:00    Copying file: 'server/models/dtlError.js'
2018-05-03T23:12:00    Copying file: 'server/routes/dtl.js'
2018-05-03T23:12:00    Copying file: 'server/routes/index.js'
2018-05-03T23:12:01    Copying file: 'server/utilities/auth.js'
2018-05-03T23:12:01    Copying file: 'server/utilities/error.js'
2018-05-03T23:12:01    Copying file: 'server/utilities/index.js'
2018-05-03T23:12:01    Copying file: 'server/utilities/logger.js'
2018-05-03T23:12:01    Copying file: 'test/common.js'
2018-05-03T23:12:01    Copying file: 'test/mocha.opts'
2018-05-03T23:12:01    Copying file: 'test/config/employees.result.json'
2018-05-03T23:12:01    Copying file: 'test/config/payload.json'
2018-05-03T23:12:01    Copying file: 'test/server/auth.js'
2018-05-03T23:12:01    Copying file: 'test/server/utilities.js'
2018-05-03T23:12:01    Copying file: 'views/default.html'
2018-05-03T23:12:01    Copying file: 'views/default.pug'
2018-05-03T23:12:01    Detecting node version spec...
2018-05-03T23:12:01    Using package.json engines.node value: 8.9.x
2018-05-03T23:12:02    Node.js versions available on the platform are: 4.4.7, 4.5.0, 6.2.2, 6.6.0, 6.9.3, 6.10.3, 6.11.0, 8.0.0, 8.1.0, 8.2.1, 8.8.1, 8.9.4, 9.4.0.
2018-05-03T23:12:02    Resolved to version 8.9.4
2018-05-03T23:12:02    Detecting npm version spec...
2018-05-03T23:12:02    Using package.json engines.npm value: 5.0.x
2018-05-03T23:12:02    NPM versions available on the platform are: 2.15.8, 2.15.9, 3.9.5, 3.10.3, 3.10.10, 5.0.3.
2018-05-03T23:12:02    Resolved to version 5.0.3
2018-05-03T23:12:02    Running "/opt/nodejs/8.9.4/bin/node" "/opt/npm/5.0.3/node_modules/npm/bin/npm-cli.js" install --production
2018-05-03T23:12:02    npm WARN lifecycle The node binary used for scripts is /usr/bin/node but npm is using /opt/nodejs/8.9.4/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
2018-05-03T23:12:13    npm WARN dtl_api@1.0.0 No repository field.
2018-05-03T23:12:13    removed 5 packages in 10.288s
2018-05-03T23:12:13    
2018-05-03T23:12:13    Finished successfully.
2018-05-03T23:12:13  Running post deployment command(s)...
2018-05-03T23:12:13  Deployment successful.
2018-05-03T23:12:14  App container will begin restart within 10 seconds.

2018-05-03 23:12:57.683 INFO  - Starting container for site
2018-05-03 23:12:57.684 INFO  - docker run -d -p 15062:8080 --name bb-dtl-service__9e0a_0 -e WEBSITE_NODE_DEFAULT_VERSION=8.9 -e APPSETTING_WEBSITE_NODE_DEFAULT_VERSION=8.9 -e WEBSITE_SITE_NAME=bb-dtl-service -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_INSTANCE_ID=fb29dfd8d91e0378f3794f42c27d2c348a5c5eb0bfc876bcc540f651b3082330 -e HTTP_LOGGING_ENABLED=1 appsvc/node:8.9.4_1804040228 ./server/server.js 

2018-05-03T23:12:59.263038964Z Starting OpenBSD Secure Shell server: sshd.
2018-05-03T23:12:59.525171581Z Generating app startup command
2018-05-03T23:12:59.538785224Z Running ./server/server.js
2018-05-03T23:12:59.559830590Z /home/site/wwwroot/server/server.js: line 1: syntax error near unexpected token `('
2018-05-03T23:12:59.559958090Z /home/site/wwwroot/server/server.js: line 1: `const express = require('express');'

2018-05-03 23:13:00.286 ERROR - Container bb-dtl-service__9e0a_0 for site bb-dtl-service__9e0a has exited, failing site start

我的server/Server.js文件内容

const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const helmet = require('helmet');
const favicon = require('serve-favicon');
const path = require('path');

const app = express();

// ======================= configuration =================================
const port = process.env.PORT || 4006;
const env = process.env.APP_ENVIRONMENT || 'unknown';

// view engine
app.set('view engine', 'pug');
app.use(express.static('public'));

// favicon
app.use(favicon(path.join(`${__dirname}/../`, 'public', 'favicon.ico')));

// use body parser so we can get info from POST and/or URL parameters
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// using morgan to log requests to the console
app.use(morgan(':remote-addr ":referrer" ":user-agent" :method :url :status - :response-time ms'));

// https://blog.risingstack.com/node-js-security-checklist/
app.use(helmet());

// ======================= routes ========================================
const apiRoutes = require('./routes');

// API ROUTES ------------------------------------------------------------
app.use('/api', apiRoutes);

// OTHER ROUTES ----------------------------------------------------------
app.get('/swagger-ui', (req, res) => {
    // show the swagger definition reader
    // html file from https://github.com/csabapalfi/swagger-ui-min
    res.redirect('/swagger.html');
});
app.all('*', (req, res) => {
    // get last commit id and show it on the page
    const lastCommitHash = process.env.SOURCE_VERSION || '';
    const lastCommitShor = lastCommitHash.length > 8 ? lastCommitHash.substr(0, 8) : '';
    res.render('default', { gitHash: lastCommitHash, gitShortHash: lastCommitShor, env });
});

// ======================= start the server ==============================
app.listen(port, () => {
    console.log(`Magic happens at http://localhost:${port}`); // eslint-disable-line
});

exports.server = app; // export for testing

有谁知道发生了什么事?

为什么容器不能接受该行?

为什么现在出现错误,因为三月以来一切正常?

我现在已经尝试了2小时的东西,没有任何意义:(

我的应用设置

5月9日更新

使用:

创建了一个简单的Dockerfile
FROM mhart/alpine-node

RUN mkdir -p /app
ADD . /app
WORKDIR /app

RUN npm install && npm update https-proxy-agent --depth 2

CMD npm start

为:

docker build .
docker run -it -p 8080:4006 -e "MONGODB_URI=mongodb://dbuser:dbpass@dsxxxxxx.mlab.com:19080/mongocollection" 5067e22e341b

> dl_api@1.0.0 start /app
> node ./server/server.js

Magic happens at http://localhost:4006

所以所有这些都可以在docker上运行:/

0 个答案:

没有答案