【问题标题】:nightmare DEBUG on Google app engine Standard EnvironmentGoogle 应用引擎标准环境上的噩梦调试
【发布时间】:2018-06-03 10:49:37
【问题描述】:

我在 Google 应用引擎上运行噩梦。我猜它不工作。 所以И想添加DEBUG=nightmare,但启动失败。

这是我的package.json

"scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4",
    "nightmare": "2.10.0"
  }

这是错误

应用程序启动错误:

appengine-hello-world@0.0.1 启动 /app

xvfb-run -a DEBUG=nightmare node app.js
/usr/bin/xvfb-run: 183: /usr/bin/xvfb-run: DEBUG=nightmare: 未找到 npm 错误!文件sh

【问题讨论】:

    标签: google-app-engine google-cloud-platform nightmare


    【解决方案1】:

    AppEngine 标准版不支持 Node.js。所以你可能在 Flex 环境中运行。 我从这个 [1] 开始。请参阅 package.json 差异。 我修改了 package.json 以匹配您的情况,并在 app.js 中尝试了噩梦。

    我可以通过替换来重现您的情况 "start": "xvfb-run -a node app.js", 在 package.json 上:

    xvfb-run -a DEBUG=nightmare node app.js 
    

    上一条命令的帮助页面显示:

    -a        --auto-servernum          try to get a free server number, starting at
                                    --server-num
    -e FILE   --error-file=FILE         file used to store xauth errors and Xvfb
                                    output (default: /dev/null)
    -f FILE   --auth-file=FILE          file used to store auth cookie
                                    (default: ./.Xauthority)
    -h        --help                    display this usage message and exit
    -n NUM    --server-num=NUM          server number to use (default: 99)
    -l        --listen-tcp              enable TCP port listening in the X server
    -p PROTO  --xauth-protocol=PROTO    X authority protocol name to use
                                    (default: xauth command's default)
    -s ARGS   --server-args=ARGS        arguments (other than server number and
                                    "-nolisten tcp") to pass to the Xvfb server
                                    (default: "-screen 0 640x480x8")
    

    我看不到任何关于 DEBUG 的信息... 所以你可能想做这样的事情:

    xvfb-run -e error.log  -a node app.js 
    

    保存错误,但我不确定。

    我将分享我的配置。

    我在运行“sudo npm install”之前和之后与您分享:

    我补充说:

    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    

    并修改: “开始”:“节点 app.js”, 到: "start": "xvfb-run -a node app.js",

    before:
    {
      "name": "appengine-hello-world",
      "description": "Simple Hello World Node.js sample for Google App Engine Flexible Environment.",
      "version": "0.0.1",
      "private": true,
      "license": "Apache-2.0",
      "author": "Google Inc.",
      "repository": {
        "type": "git",
        "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
      },
      "engines": {
        "node": ">=4.3.2"
      },
      "scripts": {
        "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
        "deploy": "gcloud app deploy",
        "start": "xvfb-run -a node app.js",
        "lint": "samples lint",
        "pretest": "npm run lint",
        "system-test": "samples test app",
        "test": "npm run system-test",
        "e2e-test": "samples test deploy"
      },
      "dependencies": {
        "express": "4.15.4"
      },
      "devDependencies": {
        "@google-cloud/nodejs-repo-tools": "1.4.17"
      },
      "cloud-repo-tools": {
        "test": {
          "app": {
            "msg": "Hello, world!"
          }
        },
        "requiresKeyFile": true,
        "requiresProjectId": true
      }
    }
    

    在“npm install”之后,文件自动更新到:

    {
      "name": "appengine-hello-world",
      "description": "Simple Hello World Node.js sample for Google App Engine Flexible Environment.",
      "version": "0.0.1",
      "private": true,
      "license": "Apache-2.0",
      "author": "Google Inc.",
      "repository": {
        "type": "git",
        "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
      },
      "engines": {
        "node": ">=4.3.2"
      },
      "scripts": {
        "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
        "deploy": "gcloud app deploy",
        "start": "xvfb-run -a node app.js",
        "lint": "samples lint",
        "pretest": "npm run lint",
        "system-test": "samples test app",
        "test": "npm run system-test",
        "e2e-test": "samples test deploy"
      },
      "dependencies": {
        "express": "4.15.4",
        "nightmare": "^2.10.0"
      },
      "devDependencies": {
        "@google-cloud/nodejs-repo-tools": "1.4.17"
      },
      "cloud-repo-tools": {
        "test": {
         "app": {
            "msg": "Hello, world!"
          }
        },
        "requiresKeyFile": true,
        "requiresProjectId": true
      }
    }
    

    我正在与噩梦分享一个sn-p js:

    'use strict';
    // [START app]
    const express = require('express');
    const app = express();
    const Nightmare = require('nightmare')
    app.get('/', (req, res) => {
      Nightmare({show: false})
      .goto('https://google.com')
      .wait('body')
      .insert('input[aria-label="Search"]', 'node-nightmare github.com')
      .click('input[type="submit"]')
      .wait(1000)
      .wait('body')
      .evaluate(function() {
         // return $('a:contains("node-nightmare")').text();
         // res.status(200).send($('a:contains("node-
    nightmare")').text()).end();
         console.log('EVALUATE');
      })
      .then(function(ret) {
         console.log('THEN');
         console.log(ret)
      });
      res.status(200).send('Hello, world!!!!!').end();
    });
    // Start the server
    const PORT = process.env.PORT || 8080;
    app.listen(PORT, () => {
      console.log(`App listening on port ${PORT}`);
      console.log('Press Ctrl+C to quit.'); 
    });
    // [END app]
    

    您可以在本地服务器上运行: npm 开始 或部署到 App Engine gcloud 应用部署

    希望对你有帮助!

    [1]https://cloud.google.com/appengine/docs/flexible/nodejs/quickstart

    【讨论】:

    • 您对“评估”的使用即使不是完全错误也令人困惑。 console.log('EVALUATE'); 永远不会出现在电子之外。与其尝试从电子发送响应,不如返回您想要的数据,然后然后在下面的.then() 中使用它。
    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 2018-10-10
    • 2019-01-25
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2021-06-22
    相关资源
    最近更新 更多