2016-02-20 13:02:22 -05:00
|
|
|
import { Parse } from 'parse/node';
|
|
|
|
|
import PromiseRouter from '../PromiseRouter';
|
2016-03-01 20:32:39 -08:00
|
|
|
import * as middleware from "../middlewares";
|
2016-02-20 13:02:22 -05:00
|
|
|
|
|
|
|
|
export class LogsRouter extends PromiseRouter {
|
|
|
|
|
|
|
|
|
|
mountRoutes() {
|
2016-03-01 20:32:39 -08:00
|
|
|
this.route('GET','/logs', middleware.promiseEnforceMasterKeyAccess, req => { return this.handleGET(req); });
|
2016-02-20 13:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns a promise for a {response} object.
|
|
|
|
|
// query params:
|
|
|
|
|
// level (optional) Level of logging you want to query for (info || error)
|
|
|
|
|
// from (optional) Start time for the search. Defaults to 1 week ago.
|
|
|
|
|
// until (optional) End time for the search. Defaults to current time.
|
|
|
|
|
// order (optional) Direction of results returned, either “asc” or “desc”. Defaults to “desc”.
|
|
|
|
|
// size (optional) Number of rows returned by search. Defaults to 10
|
|
|
|
|
handleGET(req) {
|
|
|
|
|
if (!req.config || !req.config.loggerController) {
|
2016-03-01 20:32:39 -08:00
|
|
|
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED, 'Logger adapter is not available.');
|
2016-02-20 13:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let from = req.query.from;
|
|
|
|
|
let until = req.query.until;
|
|
|
|
|
let size = req.query.size;
|
|
|
|
|
let order = req.query.order
|
|
|
|
|
let level = req.query.level;
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
from,
|
|
|
|
|
until,
|
|
|
|
|
size,
|
|
|
|
|
order,
|
2016-03-01 20:32:39 -08:00
|
|
|
level
|
|
|
|
|
};
|
2016-02-20 13:02:22 -05:00
|
|
|
|
2016-03-01 20:32:39 -08:00
|
|
|
return req.config.loggerController
|
|
|
|
|
.getLogs(options)
|
|
|
|
|
.then(result => ({ response: result }));
|
2016-02-20 13:02:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default LogsRouter;
|