sails.js 模糊的错误信息。使用 xmlHttpRequest()
sails.js vague error message. with xmlHttpRequest()
我正在使用 sails.js 从受支持的应用程序中的 newrelic insights 查询数据。我在通用控制器中的功能->newrelic->number-on-site.js 看起来像
fn: async function (inputs, exits) {
var client = new XMLHttpRequest();
client.open("GET", "https://insights-api.newrelic.com/v1/accounts/<acount_number>/query?nrql=SELECT ...", true);
client.setRequestHeader("Accept", "application/json");
client.setRequestHeader("X-Query-Key", "<my_key>");
client.send();
return exits.success();
}
请注意,该请求作为 curl 请求工作,因此数据正确,现在 sails 抛出以下警告。
warn: Files in the `controllers` directory may be traditional controllers or
action files. Traditional controllers are dictionaries of actions, with
pascal-cased filenames ending in "Controller" (e.g. MyGreatController.js).
Action files are kebab-cased (e.g. do-stuff.js) and contain a single action.
The following file was ignored for not meeting those criteria:
warn: - newrelic.ts
这句话到底想表达什么?谷歌搜索此错误消息几乎没有任何结果。它几乎接缝就像我有一个命名问题但我使用
sails generate action newrelic.numberOnSite
生成这个控制器,所以我不确定发生了什么。
编辑我的路线如下:
'/newrelic/numberOnSite': 'newrelic.numberOnSite',
以防万一。
看起来您正在混合控制器和操作,您应该 read here 或继续阅读。
传统控制器使用 pascal-cased 以 Controller 结尾,例如。 NewrelicController.js
并且,如前所述,是一个动作(函数)字典。
一个动作(函数)是 kebab 大小写的,例如。 api/controllers/newrelic/number-on-site.js
.
控制器
如果您要生成控制器,则不要包含在文件夹中...
sails generate controller newrelic numberOnSite
然后在你的 routes.js
中你会像这样路由你的路径...
'GET /newrelic/numberOnSite': 'NewrelicController.numberOnSite',
动作
如果您要生成动作,则将它们包含在文件夹中...
sails generate action newrelic/numberOnSite
然后在你的 routes.js
中你会像这样路由你的路径...
'GET /newrelic/numberOnSite': {action:'newrelic/number-on-site'},
尽管在 Sails v1.0 中引入的 Actions 比 Controllers 更受欢迎,但与动作集合相比,Controller 需要更少的代码,因为它更易于维护和调试。
我正在使用 sails.js 从受支持的应用程序中的 newrelic insights 查询数据。我在通用控制器中的功能->newrelic->number-on-site.js 看起来像
fn: async function (inputs, exits) {
var client = new XMLHttpRequest();
client.open("GET", "https://insights-api.newrelic.com/v1/accounts/<acount_number>/query?nrql=SELECT ...", true);
client.setRequestHeader("Accept", "application/json");
client.setRequestHeader("X-Query-Key", "<my_key>");
client.send();
return exits.success();
}
请注意,该请求作为 curl 请求工作,因此数据正确,现在 sails 抛出以下警告。
warn: Files in the `controllers` directory may be traditional controllers or
action files. Traditional controllers are dictionaries of actions, with
pascal-cased filenames ending in "Controller" (e.g. MyGreatController.js).
Action files are kebab-cased (e.g. do-stuff.js) and contain a single action.
The following file was ignored for not meeting those criteria:
warn: - newrelic.ts
这句话到底想表达什么?谷歌搜索此错误消息几乎没有任何结果。它几乎接缝就像我有一个命名问题但我使用
sails generate action newrelic.numberOnSite
生成这个控制器,所以我不确定发生了什么。
编辑我的路线如下:
'/newrelic/numberOnSite': 'newrelic.numberOnSite',
以防万一。
看起来您正在混合控制器和操作,您应该 read here 或继续阅读。
传统控制器使用 pascal-cased 以 Controller 结尾,例如。 NewrelicController.js
并且,如前所述,是一个动作(函数)字典。
一个动作(函数)是 kebab 大小写的,例如。 api/controllers/newrelic/number-on-site.js
.
控制器
如果您要生成控制器,则不要包含在文件夹中...
sails generate controller newrelic numberOnSite
然后在你的 routes.js
中你会像这样路由你的路径...
'GET /newrelic/numberOnSite': 'NewrelicController.numberOnSite',
动作
如果您要生成动作,则将它们包含在文件夹中...
sails generate action newrelic/numberOnSite
然后在你的 routes.js
中你会像这样路由你的路径...
'GET /newrelic/numberOnSite': {action:'newrelic/number-on-site'},
尽管在 Sails v1.0 中引入的 Actions 比 Controllers 更受欢迎,但与动作集合相比,Controller 需要更少的代码,因为它更易于维护和调试。