vee*_*MSL 1 connector loopbackjs
我正在使用loopback3.x。我想将第 3 方 API 与环回集成。为此,在使用loopback-connector-rest时显示错误“ TypeError:无法初始化未定义的连接器:无法读取未定义的属性‘root’ ”。如何修复它?
数据源配置
"restDataSource": {
"name": "restDataSource",
"baseURL": "",
"crud": true,
"connector": "rest",
"debug": false,
"options": {
"headers": {
"accept": "application/json",
"content-type": "application/json",
"authorization": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"strictSSL": false
},
"operations": [{
"template": {
"method": "POST",
"url": "https://fcm.googleapis.com/fcm/send",
"options": {
"strictSSL": true,
"useQuerystring": true
}
},
"functions": {
"notify": ["title", "text", "click_action", "keyname", "to"]
}
}]
}
Run Code Online (Sandbox Code Playgroud)
错误
TypeError: Cannot create data source "restDataSource": Cannot initialize connector "rest": Cannot read property 'root' of undefined
at /home/veena-msl/Documents/care-doc-api/node_modules/loopback-connector-rest/lib/rest-connector.js:93:28
at Array.forEach (<anonymous>)
at /home/veena-msl/Documents/care-doc-api/node_modules/loopback-connector-rest/lib/rest-connector.js:87:22
at Array.forEach (<anonymous>)
at Function.initializeDataSource [as initialize] (/home/veena-msl/Documents/care-doc-api/node_modules/loopback-connector-rest/lib/rest-connector.js:52:25)
at DataSource.setup (/home/veena-msl/Documents/care-doc-api/node_modules/loopback-datasource-juggler/lib/datasource.js:493:19)
at new DataSource (/home/veena-msl/Documents/care-doc-api/node_modules/loopback-datasource-juggler/lib/datasource.js:138:8)
at Registry.createDataSource (/home/veena-msl/Documents/care-doc-api/node_modules/loopback/lib/registry.js:364:12)
at dataSourcesFromConfig (/home/veena-msl/Documents/care-doc-api/node_modules/loopback/lib/application.js:570:19)
at Function.app.dataSource (/home/veena-msl/Documents/care-doc-api/node_modules/loopback/lib/application.js:269:14)
at /home/veena-msl/Documents/care-doc-api/node_modules/loopback-boot/lib/executor.js:191:9
at /home/veena-msl/Documents/care-doc-api/node_modules/loopback-boot/lib/executor.js:282:5
at Array.forEach (<anonymous>)
at forEachKeyedObject (/home/veena-msl/Documents/care-doc-api/node_modules/loopback-boot/lib/executor.js:281:20)
at setupDataSources (/home/veena-msl/Documents/care-doc-api/node_modules/loopback-boot/lib/executor.js:181:3)
at execute (/home/veena-msl/Documents/care-doc-api/node_modules/loopback-boot/lib/executor.js:39:3)
Run Code Online (Sandbox Code Playgroud)
在本functions节中,您定义了一个notify接受多个输入参数的函数:title, text, click_action, keyname, to。但是,本template节没有提供有关如何将这些参数映射到 HTTP 请求的任何信息。例如,应该title通过 URL 查询还是在请求正文中发送?
IIUC,您正在尝试使用旧版 Firbase Cloud Messaging HTTP API,如下所述: https: //firebase.google.com/docs/cloud-messaging/http-server-ref根据该文档,我认为您的所有参数函数应在请求正文中发送。
当输入参数未映射到任何 HTTP 源时,LoopBack 的 REST 连接器似乎无法正确检测和处理这种情况。它不应该崩溃,请随时在https://github.com/strongloop/loopback-connector-rest/issues中打开错误报告
这是不会使服务器崩溃的配置。我没有 Firebase 帐户来验证它是否按预期工作。
"template": {
"method": "POST",
"url": "https://fcm.googleapis.com/fcm/send",
"options": {
"strictSSL": true,
"useQuerystring": true
},
"body": {
"title": "{title:string}",
"text": "{text:string}",
"click_action": "{click_action:string}",
"keyname": "{keyname:string}",
"to": "{to:string}"
}
},
Run Code Online (Sandbox Code Playgroud)
您可以在连接器文档中了解有关配置输入参数的不同方法的更多信息:https://loopback.io/doc/en/lb3/REST-connector.html#defining-a-custom-method-using-a-template
| 归档时间: |
|
| 查看次数: |
1991 次 |
| 最近记录: |