-
-
Notifications
You must be signed in to change notification settings - Fork 10k
/
routes.js
227 lines (184 loc) · 9.57 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const express = require('express');
const apiCanary = require('../../../../api/canary');
const mw = require('./middleware');
const shared = require('../../../shared');
// Handling uploads & imports
const upload = shared.middlewares.upload;
module.exports = function apiRoutes() {
const router = express.Router();
// alias delete with del
router.del = router.delete;
router.use(shared.middlewares.api.cors);
const http = apiCanary.http;
// ## Public
router.get('/site', mw.publicAdminApi, http(apiCanary.site.read));
// ## Configuration
router.get('/config', mw.authAdminApi, http(apiCanary.config.read));
// ## Posts
router.get('/posts', mw.authAdminApi, http(apiCanary.posts.browse));
router.post('/posts', mw.authAdminApi, http(apiCanary.posts.add));
router.get('/posts/:id', mw.authAdminApi, http(apiCanary.posts.read));
router.get('/posts/slug/:slug', mw.authAdminApi, http(apiCanary.posts.read));
router.put('/posts/:id', mw.authAdminApi, http(apiCanary.posts.edit));
router.del('/posts/:id', mw.authAdminApi, http(apiCanary.posts.destroy));
// ## Pages
router.get('/pages', mw.authAdminApi, http(apiCanary.pages.browse));
router.post('/pages', mw.authAdminApi, http(apiCanary.pages.add));
router.get('/pages/:id', mw.authAdminApi, http(apiCanary.pages.read));
router.get('/pages/slug/:slug', mw.authAdminApi, http(apiCanary.pages.read));
router.put('/pages/:id', mw.authAdminApi, http(apiCanary.pages.edit));
router.del('/pages/:id', mw.authAdminApi, http(apiCanary.pages.destroy));
// # Integrations
router.get('/integrations', mw.authAdminApi, http(apiCanary.integrations.browse));
router.get('/integrations/:id', mw.authAdminApi, http(apiCanary.integrations.read));
router.post('/integrations', mw.authAdminApi, http(apiCanary.integrations.add));
router.put('/integrations/:id', mw.authAdminApi, http(apiCanary.integrations.edit));
router.del('/integrations/:id', mw.authAdminApi, http(apiCanary.integrations.destroy));
// ## Schedules
router.put('/schedules/:resource/:id', mw.authAdminApiWithUrl, http(apiCanary.schedules.publish));
// ## Settings
router.get('/settings/routes/yaml', mw.authAdminApi, http(apiCanary.settings.download));
router.post('/settings/routes/yaml',
mw.authAdminApi,
upload.single('routes'),
shared.middlewares.validation.upload({type: 'routes'}),
http(apiCanary.settings.upload)
);
router.get('/settings', mw.authAdminApi, http(apiCanary.settings.browse));
router.get('/settings/:key', mw.authAdminApi, http(apiCanary.settings.read));
router.put('/settings', mw.authAdminApi, http(apiCanary.settings.edit));
// ## Users
router.get('/users', mw.authAdminApi, http(apiCanary.users.browse));
router.get('/users/:id', mw.authAdminApi, http(apiCanary.users.read));
router.get('/users/slug/:slug', mw.authAdminApi, http(apiCanary.users.read));
// NOTE: We don't expose any email addresses via the public api.
router.get('/users/email/:email', mw.authAdminApi, http(apiCanary.users.read));
router.put('/users/password', mw.authAdminApi, http(apiCanary.users.changePassword));
router.put('/users/owner', mw.authAdminApi, http(apiCanary.users.transferOwnership));
router.put('/users/:id', mw.authAdminApi, http(apiCanary.users.edit));
router.del('/users/:id', mw.authAdminApi, http(apiCanary.users.destroy));
// ## Tags
router.get('/tags', mw.authAdminApi, http(apiCanary.tags.browse));
router.get('/tags/:id', mw.authAdminApi, http(apiCanary.tags.read));
router.get('/tags/slug/:slug', mw.authAdminApi, http(apiCanary.tags.read));
router.post('/tags', mw.authAdminApi, http(apiCanary.tags.add));
router.put('/tags/:id', mw.authAdminApi, http(apiCanary.tags.edit));
router.del('/tags/:id', mw.authAdminApi, http(apiCanary.tags.destroy));
// ## Members
router.get('/members', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.browse));
router.post('/members', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.add));
router.get('/members/csv', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.exportCSV));
router.post('/members/csv',
shared.middlewares.labs.members,
mw.authAdminApi,
upload.single('membersfile'),
shared.middlewares.validation.upload({type: 'members'}),
http(apiCanary.members.importCSV)
);
router.get('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.read));
router.put('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.edit));
router.del('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, http(apiCanary.members.destroy));
// ## Roles
router.get('/roles/', mw.authAdminApi, http(apiCanary.roles.browse));
// ## Slugs
router.get('/slugs/:type/:name', mw.authAdminApi, http(apiCanary.slugs.generate));
// ## Themes
router.get('/themes/', mw.authAdminApi, http(apiCanary.themes.browse));
router.get('/themes/:name/download',
mw.authAdminApi,
http(apiCanary.themes.download)
);
router.post('/themes/upload',
mw.authAdminApi,
upload.single('file'),
shared.middlewares.validation.upload({type: 'themes'}),
http(apiCanary.themes.upload)
);
router.put('/themes/:name/activate',
mw.authAdminApi,
http(apiCanary.themes.activate)
);
router.del('/themes/:name',
mw.authAdminApi,
http(apiCanary.themes.destroy)
);
// ## Notifications
router.get('/notifications', mw.authAdminApi, http(apiCanary.notifications.browse));
router.post('/notifications', mw.authAdminApi, http(apiCanary.notifications.add));
router.del('/notifications/:notification_id', mw.authAdminApi, http(apiCanary.notifications.destroy));
// ## DB
router.get('/db', mw.authAdminApi, http(apiCanary.db.exportContent));
router.post('/db',
mw.authAdminApi,
upload.single('importfile'),
shared.middlewares.validation.upload({type: 'db'}),
http(apiCanary.db.importContent)
);
router.del('/db', mw.authAdminApi, http(apiCanary.db.deleteAllContent));
router.post('/db/backup',
mw.authAdminApi,
http(apiCanary.db.backupContent)
);
// ## Mail
router.post('/mail', mw.authAdminApi, http(apiCanary.mail.send));
router.post('/mail/test', mw.authAdminApi, http(apiCanary.mail.sendTest));
// ## Slack
router.post('/slack/test', mw.authAdminApi, http(apiCanary.slack.sendTest));
// ## Sessions
router.get('/session', mw.authAdminApi, http(apiCanary.session.read));
// We don't need auth when creating a new session (logging in)
router.post('/session',
shared.middlewares.brute.globalBlock,
shared.middlewares.brute.userLogin,
http(apiCanary.session.add)
);
router.del('/session', mw.authAdminApi, http(apiCanary.session.delete));
// ## Authentication
router.post('/authentication/passwordreset',
shared.middlewares.brute.globalReset,
shared.middlewares.brute.userReset,
http(apiCanary.authentication.generateResetToken)
);
router.put('/authentication/passwordreset', shared.middlewares.brute.globalBlock, http(apiCanary.authentication.resetPassword));
router.post('/authentication/invitation', http(apiCanary.authentication.acceptInvitation));
router.get('/authentication/invitation', http(apiCanary.authentication.isInvitation));
router.post('/authentication/setup', http(apiCanary.authentication.setup));
router.put('/authentication/setup', mw.authAdminApi, http(apiCanary.authentication.updateSetup));
router.get('/authentication/setup', http(apiCanary.authentication.isSetup));
// ## Images
router.post('/images/upload',
mw.authAdminApi,
upload.single('file'),
shared.middlewares.validation.upload({type: 'images'}),
shared.middlewares.image.normalize,
http(apiCanary.images.upload)
);
// ## Invites
router.get('/invites', mw.authAdminApi, http(apiCanary.invites.browse));
router.get('/invites/:id', mw.authAdminApi, http(apiCanary.invites.read));
router.post('/invites', mw.authAdminApi, http(apiCanary.invites.add));
router.del('/invites/:id', mw.authAdminApi, http(apiCanary.invites.destroy));
// ## Redirects (JSON based)
router.get('/redirects/json', mw.authAdminApi, http(apiCanary.redirects.download));
router.post('/redirects/json',
mw.authAdminApi,
upload.single('redirects'),
shared.middlewares.validation.upload({type: 'redirects'}),
http(apiCanary.redirects.upload)
);
// ## Webhooks (RESTHooks)
router.post('/webhooks', mw.authAdminApi, http(apiCanary.webhooks.add));
router.put('/webhooks/:id', mw.authAdminApi, http(apiCanary.webhooks.edit));
router.del('/webhooks/:id', mw.authAdminApi, http(apiCanary.webhooks.destroy));
// ## Oembed (fetch response from oembed provider)
router.get('/oembed', mw.authAdminApi, http(apiCanary.oembed.read));
// ## Actions
router.get('/actions', mw.authAdminApi, http(apiCanary.actions.browse));
// ## Email Preview
router.get('/email_preview/posts/:id', mw.authAdminApi, http(apiCanary.email_preview.read));
router.post('/email_preview/posts/:id', mw.authAdminApi, http(apiCanary.email_preview.sendTestEmail));
// ## Emails
router.get('/emails/:id', mw.authAdminApi, http(apiCanary.emails.read));
router.put('/emails/:id/retry', mw.authAdminApi, http(apiCanary.emails.retry));
return router;
};