部署中有没有办法将 collection 映射到不同的端点?
Is there a way in deployd to map a collection to a different endpoint?
我有一个名为 customer_devices 的 collection,我无法更改名称。我可以通过 deployd as /devices 公开它吗?怎么样?
我能想到几种方法。如果您真的只是想重命名该集合,您可以从仪表板执行此操作,正如@thomasb 在他的回答中提到的那样。
或者,您可以创建 "proxy" 事件资源 devices
并将所有查询转发到 customer_devices
。例如,在 devices/get.js
你会说
dpd.customer_devices.get(query, function(res, err) {
if (err) cancel(err);
setResult(res);
});
更新
最后,这里有一个 "hack" 将所有请求从一个资源路径重定向到另一个路径。这是未经充分测试的,因此使用风险自负。这要求您按照 here 的说明设置自己的服务器。完成后,您可以使用此代码段修改路由行为:
server.on('listening', function() {
var customer_devices = server.router.resources.filter(function (res) {
return res.path === '/customer_devices';
})[0];
// Make a copy of the Object's prototype
var devices = Object.create(customer_devices);
// Shallow copy the properties
devices = extend(devices, customer_devices);
// Change the routing path
devices.path = "/devices";
// Add back to routing cache
server.router.resources.push(devices);
});
这将获取您的 customer_devices
资源,复制它,更改路径,然后将其重新插入缓存路由 table。我测试了它并且它有效,但我不保证它是安全的或者是个好主意...
你不能通过仪表板更改名称吗?
- 将鼠标悬停在您的 collection customer_devices
上
- 单击向下箭头
- Select 'Rename'
- 输入新名称并点击'Rename'
我有一个名为 customer_devices 的 collection,我无法更改名称。我可以通过 deployd as /devices 公开它吗?怎么样?
我能想到几种方法。如果您真的只是想重命名该集合,您可以从仪表板执行此操作,正如@thomasb 在他的回答中提到的那样。
或者,您可以创建 "proxy" 事件资源 devices
并将所有查询转发到 customer_devices
。例如,在 devices/get.js
你会说
dpd.customer_devices.get(query, function(res, err) {
if (err) cancel(err);
setResult(res);
});
更新
最后,这里有一个 "hack" 将所有请求从一个资源路径重定向到另一个路径。这是未经充分测试的,因此使用风险自负。这要求您按照 here 的说明设置自己的服务器。完成后,您可以使用此代码段修改路由行为:
server.on('listening', function() {
var customer_devices = server.router.resources.filter(function (res) {
return res.path === '/customer_devices';
})[0];
// Make a copy of the Object's prototype
var devices = Object.create(customer_devices);
// Shallow copy the properties
devices = extend(devices, customer_devices);
// Change the routing path
devices.path = "/devices";
// Add back to routing cache
server.router.resources.push(devices);
});
这将获取您的 customer_devices
资源,复制它,更改路径,然后将其重新插入缓存路由 table。我测试了它并且它有效,但我不保证它是安全的或者是个好主意...
你不能通过仪表板更改名称吗?
- 将鼠标悬停在您的 collection customer_devices 上
- 单击向下箭头
- Select 'Rename'
- 输入新名称并点击'Rename'