0

I have a collection called customer_devices and I can't change the name. Can I expose it via deployd as /devices ? How?

Felipe Plets
  • 7,230
  • 3
  • 36
  • 60

2 Answers2

1

There are a few ways that I can think of. If you really just want to rename the collection, you can do so from the dashboard, as @thomasb mentioned in his answer.

Alternatively, you can create a "proxy" event resource devices and forward all queries to customer_devices. For example, in devices/get.js you would say

dpd.customer_devices.get(query, function(res, err) {
    if (err) cancel(err);
    setResult(res);
});

Update
Finally, here is a "hack" to redirect all requests from one resource path to a different path. This is poorly tested so use at your own risk. This requires that you set up your own server as explained here. Once you have that, you can modify the routing behaviour using this snippet:

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);
});

This will take your customer_devices resource, copy it, change the path, and re-insert it into the cached routing table. I tested it and it works, but I won't guarantee that it's safe or a good idea...

DaGaMs
  • 1,521
  • 17
  • 26
  • The truth is that the first way does not accomplish the job, as I can't rename the collection. Although the second works, it's not a solution only a work around and as I have many different collections with the same problem, including the "user" collection, this is also not suitable. =( – Felipe Plets Nov 12 '15 at 17:11
  • Maybe I'm not really understanding your problem then. Why can't you rename the collection? – DaGaMs Nov 12 '15 at 23:01
  • So, what you want is a way to forward all requests to a certain endpoint to a different endpoint, without having to write any proxy code? – DaGaMs Nov 12 '15 at 23:02
  • exactly, I can't rename because I have other services using the same database and this services need collections with specific prefix, so I want routes instead of proxying via code. Just a map like route("customer_devices", "devices"). – Felipe Plets Nov 13 '15 at 14:49
  • Let me know if that last option that I just added does the trick – DaGaMs Nov 13 '15 at 22:32
0

Can't you change the name via dashboard?

  1. Mouseover your collection customer_devices
  2. Click the down arrow
  3. Select 'Rename'
  4. Enter the new name and click 'Rename'
thomasb
  • 95
  • 8
  • Hi @thomasb thanks for trying to help, but this is not the case, is not that I'm not able to change the name, is that I'm not allowed because there are other services using the same collections and has a specific prefix. I want a solution like a route that points the endpoint to another collection. Something like route("customer_devices", "devices") – Felipe Plets Nov 13 '15 at 14:52
  • Good point, I had totally forgotten that you can also do that... Will edit my post... – DaGaMs Nov 13 '15 at 20:46
  • 1
    @FelipePlets Oh sorry, I misunderstood your question. In this case [/lib/router.js](https://github.com/deployd/deployd/blob/master/lib/router.js) could be a good starting point to dig into it. – thomasb Nov 13 '15 at 20:47