|
1 import ENV from 'app-client/config/environment'; |
|
2 import _ from 'lodash/lodash'; |
|
3 |
|
4 export default function() { |
|
5 |
|
6 // These comments are here to help you get started. Feel free to delete them. |
|
7 |
|
8 /* |
|
9 Config (with defaults). |
|
10 |
|
11 Note: these only affect routes defined *after* them! |
|
12 */ |
|
13 // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server |
|
14 // this.namespace = ''; // make this `api`, for example, if your API is namespaced |
|
15 this.namespace = ENV.baseURL.replace(/\/$/,"")+'/api/v1'; |
|
16 // this.timing = 400; // delay for each request, automatically set to 0 during testing |
|
17 |
|
18 this.get('/documents'); |
|
19 this.get('/documents/:id', function(db, request) { |
|
20 var docId = decodeURIComponent(request.params.id); |
|
21 console.log("DOC ID", docId); |
|
22 |
|
23 return { |
|
24 'document': db.documents.find(docId) |
|
25 }; |
|
26 }); |
|
27 |
|
28 this.get('/languages', function(db) { |
|
29 var res = {}; |
|
30 _.each(db.languages, function(lang) { |
|
31 res[lang.id] = lang.count; |
|
32 }); |
|
33 return res; |
|
34 }); |
|
35 |
|
36 /* |
|
37 Route shorthand cheatsheet |
|
38 */ |
|
39 /* |
|
40 GET shorthands |
|
41 |
|
42 // Collections |
|
43 this.get('/contacts'); |
|
44 this.get('/contacts', 'users'); |
|
45 this.get('/contacts', ['contacts', 'addresses']); |
|
46 |
|
47 // Single objects |
|
48 this.get('/contacts/:id'); |
|
49 this.get('/contacts/:id', 'user'); |
|
50 this.get('/contacts/:id', ['contact', 'addresses']); |
|
51 */ |
|
52 |
|
53 /* |
|
54 POST shorthands |
|
55 |
|
56 this.post('/contacts'); |
|
57 this.post('/contacts', 'user'); // specify the type of resource to be created |
|
58 */ |
|
59 |
|
60 /* |
|
61 PUT shorthands |
|
62 |
|
63 this.put('/contacts/:id'); |
|
64 this.put('/contacts/:id', 'user'); // specify the type of resource to be updated |
|
65 */ |
|
66 |
|
67 /* |
|
68 DELETE shorthands |
|
69 |
|
70 this.del('/contacts/:id'); |
|
71 this.del('/contacts/:id', 'user'); // specify the type of resource to be deleted |
|
72 |
|
73 // Single object + related resources. Make sure parent resource is first. |
|
74 this.del('/contacts/:id', ['contact', 'addresses']); |
|
75 */ |
|
76 |
|
77 /* |
|
78 Function fallback. Manipulate data in the db via |
|
79 |
|
80 - db.{collection} |
|
81 - db.{collection}.find(id) |
|
82 - db.{collection}.where(query) |
|
83 - db.{collection}.update(target, attrs) |
|
84 - db.{collection}.remove(target) |
|
85 |
|
86 // Example: return a single object with related models |
|
87 this.get('/contacts/:id', function(db, request) { |
|
88 var contactId = +request.params.id; |
|
89 |
|
90 return { |
|
91 contact: db.contacts.find(contactId), |
|
92 addresses: db.addresses.where({contact_id: contactId}) |
|
93 }; |
|
94 }); |
|
95 |
|
96 */ |
|
97 } |
|
98 |
|
99 /* |
|
100 You can optionally export a config that is only loaded during tests |
|
101 export function testConfig() { |
|
102 |
|
103 } |
|
104 */ |