forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing-routes.js
73 lines (65 loc) · 2.08 KB
/
testing-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
// testing-routes.js
var express = require('express'),
cache = require('./cache'),
middlewares = require('./middlewares'),
rack = require('hat').rack();
var router = express.Router();
// creates a unique app in the cache, with a collection prefix
function createApp(req, res) {
var appId = rack();
cache.apps[appId] = {
'collectionPrefix': appId + '_',
'masterKey': 'master'
};
var keys = {
'application_id': appId,
'client_key': 'unused',
'windows_key': 'unused',
'javascript_key': 'unused',
'webhook_key': 'unused',
'rest_api_key': 'unused',
'master_key': 'master'
};
res.status(200).send(keys);
}
// deletes all collections with the collectionPrefix of the app
function clearApp(req, res) {
if (!req.auth.isMaster) {
return res.status(401).send({"error": "unauthorized"});
}
req.database.deleteEverything().then(() => {
res.status(200).send({});
});
}
// deletes all collections and drops the app from cache
function dropApp(req, res) {
if (!req.auth.isMaster) {
return res.status(401).send({"error": "unauthorized"});
}
req.database.deleteEverything().then(() => {
delete cache.apps[req.config.applicationId];
res.status(200).send({});
});
}
// Lets just return a success response and see what happens.
function notImplementedYet(req, res) {
res.status(200).send({});
}
router.post('/rest_clear_app',
middlewares.handleParseHeaders, clearApp);
router.post('/rest_block',
middlewares.handleParseHeaders, notImplementedYet);
router.post('/rest_mock_v8_client',
middlewares.handleParseHeaders, notImplementedYet);
router.post('/rest_unmock_v8_client',
middlewares.handleParseHeaders, notImplementedYet);
router.post('/rest_verify_analytics',
middlewares.handleParseHeaders, notImplementedYet);
router.post('/rest_create_app', createApp);
router.post('/rest_drop_app',
middlewares.handleParseHeaders, dropApp);
router.post('/rest_configure_app',
middlewares.handleParseHeaders, notImplementedYet);
module.exports = {
router: router
};