环境ios, avoscloud 版本 0.9.1

在本地终端机执行 avoscloud , 在浏覧器打开http://localhost:3001/ ,或http://localhost:3000/ 都会出现错误

已经重新安装了 avoscloud-code , 错误讯息一样。现在我无法开发,进度落後,请尽快给出解决方法

提示:您可以敲入 rs 命令并回车来重启本进程
提示:您可以使用 http://localhost:30011 测试 Cloud 函数
undefined:1
undefined
^

SyntaxError: Unexpected token u
at Object.parse (native)
at Request.callback (/usr/local/lib/nodemodules/avoscloud-code/lib/testUtilServer.js:101:17)
at self.callback (/usr/local/lib/node_modules/avoscloud-code/node_modules/request/request.js:199:22)
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)
at ClientRequest.self.clientErrorHandler (/usr/local/lib/node_modules/avoscloud-code/node_modules/request/request.js:343:10)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at Socket.socketErrorListener (httpclient.js:265:9)
at emitOne (events.js:77:13)

你好,这个错误发生在从 Node SDK 获取云函数信息时,请问在启动 avoscloud 后是否可以访问 http://localhost:3000/1.1/functions/_ops/metadatas ?结果是什么样的?

环境ios, avoscloud 版本 0.9.1

在本地终端机执行 avoscloud , 在浏覧器打开http://localhost:3001/ ,或http://localhost:3000/ 都会出现错误

已经重新安装了 avoscloud-code , 错误讯息一样。现在我无法开发,进度落後,请尽快给出解决方法

提示:您可以敲入 rs 命令并回车来重启本进程
提示:您可以使用 http://localhost:30012 测试 Cloud 函数
undefined:1
undefined
^

SyntaxError: Unexpected token u
at Object.parse (native)
at Request.callback (/usr/local/lib/nodemodules/avoscloud-code/lib/testUtilServer.js:101:17)
at self.callback (/usr/local/lib/node_modules/avoscloud-code/node_modules/request/request.js:199:22)
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)
at ClientRequest.self.clientErrorHandler (/usr/local/lib/node_modules/avoscloud-code/node_modules/request/request.js:343:10)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at Socket.socketErrorListener (httpclient.js:265:9)
at emitOne (events.js:77:13)

网页端:

Not Found

404

Error: Not Found
at /Users/staging/Desktop/website_/node/generate_plist/app.js:30:13
at Layer.handle as handle_request
at trim_prefix (/Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:312:13)
at /Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:330:12)
at next (/Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:271:10)
at /Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:618:15
at next (/Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:256:14)
at Function.handle (/Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:176:3)
at router (/Users/staging/Desktop/website_/node/generate_plist/node_modules/express/lib/router/index.js:46:12)

终端机:

提示:您可以敲入 rs 命令并回车来重启本进程
提示:您可以使用 http://localhost:3001 测试 Cloud 函数
http://localhost:3000/1.1/functions/_ops/metadatasevents.js:141
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:860:11)
at exports._exceptionWithHostPort (util.js:883:20)
at Server._listen2 (net.js:1234:14)
at listen (net.js:1270:10)
at Server.listen (net.js:1366:5)
at EventEmitter.listen (/Volumes/PETER_32GB/sourceTree/istagingportalcloudcode/node_modules/express/lib/application.js:617:24)
at Object. (/Volumes/PETER_32GB/sourceTree/istagingportalcloudcode/server.js:18:5)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
at node.js:972:3

那就好,现在算是正常了

它仍然不能正常运作,错误讯息依旧,请提供解决方法。
如果你需要更多讯息我可以提供

提示:您可以敲入 rs 命令并回车来重启本进程
提示:您可以使用 http://localhost:3001 测试 Cloud 函数
undefined:1
undefined
^

SyntaxError: Unexpected token u
at Object.parse (native)
at Request.callback (/usr/local/lib/nodemodules/avoscloud-code/lib/testUtilServer.js:101:17)
at self.callback (/usr/local/lib/node_modules/avoscloud-code/node_modules/request/request.js:199:22)
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)
at ClientRequest.self.clientErrorHandler (/usr/local/lib/node_modules/avoscloud-code/node_modules/request/request.js:343:10)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at Socket.socketErrorListener (httpclient.js:265:9)
at emitOne (events.js:77:13)

启动命令行工具后,再开一个终端窗口,执行:

curl -v http://localhost:3000/1.1/functions/_ops/metadatas -H 'x-avoscloud-application-id: <appId>' -H 'x-avoscloud-master-key: <masterKey>'

然后告诉我们一下结果,记得自己替换命令里面的 appId 和 masterKey。

以下是执行结果

curl -v http://localhost:3000/1.1/functions/_ops/metadatas -H 'x-avoscloud-application-id: ' -H 'x-avoscloud-master-key: '

  • Hostname was NOT found in DNS cache
  • Trying ::1...
  • Connected to localhost (::1) port 3000 (#0)
    > GET /1.1/functions/_ops/metadatas HTTP/1.1
    > User-Agent: curl/7.37.1
    > Host: localhost:3000
    > Accept: /
    > x-avoscloud-application-id:
    > x-avoscloud-master-key:
    >
    < HTTP/1.1 200 OK
    < X-Powered-By: Express
    < Access-Control-Allow-Origin: *
    < Content-Type: application/json; charset=UTF-8
    < Date: Tue, 23 Feb 2016 07:11:45 GMT
    < Connection: keep-alive
    < Content-Length: 1555
    <
  • Connection #0 to host localhost left intact
    {"result":["CardHash","getBuildingAdminReportACL","getConversationIdByName","resetPasswd","uploadBusCardAndRealName","createBuildingTemp","updateBuildingTemp","createFakeBuilding","createFakeReport","getBuildingInfo","createAgentUnderAdmin","createAgentUnderAdminWithoutLogin","createUser","getNewPhoneVerifyCode","iStagingHomePaymentGateway","iStagingHomeSubscription","Payout","loginuser","loginuserUnderAdmin","getAllCrossSellingGPSInfo","getAllCrossSellingVersionInfo","getAllCrossSellingBuildings","getCurrentSellingGPSInfo","getCurrentSellingVersionInfo","getCurrentSellingBuildings","getDistTree","getCrossSellingBuildingById","saveUserReportData","getUserReportData","getUserReportDataByBuilding","updateUserCreditCard","getCreditCard","listReferrals","updateName","relationBuilderUserBuilding","relationBuilderUserReportProgress","relationBuilder","userTree","reportOfBuilding","reportOfBuilStagingdeMBP:~ staStagingdeMBP:~ staStagingdeMBPStaginStagingdeMBP:~ staging$

"reportOfBuilding","reportOfBuilStagingdeMBP:~

从这个末尾来看,响应结果好像被截断了,导致结果不是一个 JSON 结构,然后解析出错了。

能不能麻烦确认下被截断的原因?

还有 curl 请求的详情里有 appId 和 masterKey 的信息,我帮你编辑删除掉了。

安全起见,建议你重置下 masterKey,在应用设置里有这个功能。

尝试把 leanengine 的路由(类似这样的代码: app.use(cloud);)放在尽量靠前的位置,避免被其他中间件影响。