【问题标题】:node.js + express error: cannot read property 'url' of undefinednode.js + express 错误:无法读取未定义的属性“url”
【发布时间】:2012-06-28 04:54:36
【问题描述】:

我是 Node.js 的新手,安装它是为了试用 DrupalChat (v7dev) 模块。我相信这个问题出在 node.js 或 express 上,因为我超出了加载聊天模块设置的阶段。尝试启动聊天服务器时遇到以下输出

Extension loaded: drupalchat_nodejs.server.extension.js
Started http server.
   info  - socket.io started

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot read property 'url' of undefined
    at Function.handle (/usr/local/lib/node_modules/npm/node_modules/express/node_modules/connect/lib/proto.js:105:18)
    at Server.app (/usr/local/lib/node_modules/npm/node_modules/express/node_modules/connect/lib/connect.js:60:31)
    at Server.serverListening (/usr/local/lib/node_modules/npm/node_modules/socket.io/node_modules/policyfile/lib/server.js:136:16)
    at Server.g (events.js:154:14)
    at Server.emit (events.js:64:17)
    at Array.1 (net.js:710:10)
    at EventEmitter._tickCallback (node.js:192:40)

我记得安装 express 时,它给出了类似“.... bugs['web'] 应该是 bugs['url']”的警告(我不记得前缀)

那么服务器是否正在尝试读取(API?)变量“url”但当前是“web”?

我的所有模块都是最新的,我应该降级吗?或者有没有办法使用另一个模块来解决这个问题?

编辑: 第 201 行是最后一行 (delete authenticatedClients[authData.authToken];)... 我刚刚添加到整个函数以获得正确的上下文

var authenticateClientCallback = function (error, response, body) {
  if (error) {
    console.log("Error with authenticate client request:", error);
    return;
  }
  if (response.statusCode == 404) {
    if (settings.debug) {
      console.log('Backend authentication url not found, full response info:', response);
    }
    else {
      console.log('Backend authentication url not found.');
    }
    return;
  }

  var authData = false;
  try {
    authData = JSON.parse(body);
  }
  catch (exception) {
    console.log('Failed to parse authentication message:', exception);
    if (settings.debug) {
      console.log('Failed message string: ' + body);
    }
    return;
  }
  if (!checkServiceKey(authData.serviceKey)) {
    console.log('Invalid service key "', authData.serviceKey, '"');
    return;
  }
  if (authData.nodejsValidAuthToken) {
    if (settings.debug) {
      console.log('Valid login for uid "', authData.uid, '"');
    }
    setupClientConnection(authData.clientId, authData, authData.contentTokens);
    authenticatedClients[authData.authToken] = authData;
  }
  else {
    console.log('Invalid login for uid "', authData.uid, '"');
    delete authenticatedClients[authData.authToken];
  }
}

【问题讨论】:

  • 你能不能显示 node.js:201 或者更多。
  • 我添加了它,现在我想知道它是否是 DrupalChat 配置中的非必需设置(serviceKey),开发人员可能要求但没有反映在他的代码/cmets 中跨度>
  • v7 不稳定,你可以在这里找到一些东西:drupal.org/project/issues/…
  • 嘿,是的,我看过了,drupal 7 模块缺少很多文档并使用 node.js,我现在正在慢慢玩配置变量......我想我'会将该评论标记为正确...不知道在此模块的当前状态下还要花多少时间来处理此模块
  • @racar 你能暂时把这个评论作为答案吗

标签: node.js express


【解决方案1】:

根据@thesnufkin 的帖子,当前提取的底层 express 版本似乎不稳定。回滚到 2.5.9,您应该一切顺利:

npm 卸载快递 npm install express@2.5.9

【讨论】:

    【解决方案2】:

    根据要求,

    drupal 的 v7 聊天模块不稳定。你不应该在生产中使用它。

    检查错误:http://drupal.org/project/issues/drupalchat?status=All&categories=All

    查看论坛:http://drupalchat7.botskool.co.in/?q=forum

    仍在寻找新的维护者: “需要新的维护者 - 如果您有兴趣,请联系 beejeebus!”。

    【讨论】:

      【解决方案3】:

      nodejs 模块有这个问题,所以我认为它与 drupalchat 服务器无关。这是问题所在:http://drupal.org/node/1537702

      【讨论】:

      • 嘿,谢谢你指点我,我会监视那个线程......你很快就抽签了,这个问题只是今天才提出的! :)
      【解决方案4】:

      在 DrupalChat 中使用 node.js 作为后端的选项目前正在开发中。它还取决于您下载 DrupalChat 的时间(日期),因为开发代码每天都会更新,如果提交了新代码。

      请在此链接上提出相同的问题 - http://drupal.org/project/issues/drupalchat?status=All&categories=All

      谢谢,

      暗黑

      【讨论】:

      • P.S. - 此外,DrupalChat 模块不需要新的维护者,如当前标记的答案所示。它正在积极开发中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      相关资源
      最近更新 更多