Style improvements (#2475)
* HooksRouter is enabled by default * Adds middleswares on PromiseRouter, fixes #2410 * Move testing line to helper * Modernize middlewares.js * Moves DB uniqueness initialization to DBController, modernize * Moves testing related code to spec folder * remove unused _removeHook function * Adds tests, docs for Analytics and improvements * nit * moves back TestUtils
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import AppCache from './cache';
|
||||
import log from './logger';
|
||||
|
||||
var Parse = require('parse/node').Parse;
|
||||
|
||||
var auth = require('./Auth');
|
||||
var Config = require('./Config');
|
||||
var ClientSDK = require('./ClientSDK');
|
||||
import AppCache from './cache';
|
||||
import log from './logger';
|
||||
import Parse from 'parse/node';
|
||||
import auth from './Auth';
|
||||
import Config from './Config';
|
||||
import ClientSDK from './ClientSDK';
|
||||
|
||||
// Checks that the request is authorized for this app and checks user
|
||||
// auth too.
|
||||
@@ -13,7 +11,7 @@ var ClientSDK = require('./ClientSDK');
|
||||
// Adds info to the request:
|
||||
// req.config - the Config for this app
|
||||
// req.auth - the Auth for this request
|
||||
function handleParseHeaders(req, res, next) {
|
||||
export function handleParseHeaders(req, res, next) {
|
||||
var mountPathLength = req.originalUrl.length - req.url.length;
|
||||
var mountPath = req.originalUrl.slice(0, mountPathLength);
|
||||
var mount = req.protocol + '://' + req.get('host') + mountPath;
|
||||
@@ -205,7 +203,7 @@ function decodeBase64(str) {
|
||||
return new Buffer(str, 'base64').toString()
|
||||
}
|
||||
|
||||
var allowCrossDomain = function(req, res, next) {
|
||||
export function allowCrossDomain(req, res, next) {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, Content-Type');
|
||||
@@ -219,7 +217,7 @@ var allowCrossDomain = function(req, res, next) {
|
||||
}
|
||||
};
|
||||
|
||||
var allowMethodOverride = function(req, res, next) {
|
||||
export function allowMethodOverride(req, res, next) {
|
||||
if (req.method === 'POST' && req.body._method) {
|
||||
req.originalMethod = req.method;
|
||||
req.method = req.body._method;
|
||||
@@ -228,7 +226,7 @@ var allowMethodOverride = function(req, res, next) {
|
||||
next();
|
||||
};
|
||||
|
||||
var handleParseErrors = function(err, req, res, next) {
|
||||
export function handleParseErrors(err, req, res, next) {
|
||||
// TODO: Add logging as those errors won't make it to the PromiseRouter
|
||||
if (err instanceof Parse.Error) {
|
||||
var httpStatus;
|
||||
@@ -259,7 +257,7 @@ var handleParseErrors = function(err, req, res, next) {
|
||||
next(err);
|
||||
};
|
||||
|
||||
function enforceMasterKeyAccess(req, res, next) {
|
||||
export function enforceMasterKeyAccess(req, res, next) {
|
||||
if (!req.auth.isMaster) {
|
||||
res.status(403);
|
||||
res.end('{"error":"unauthorized: master key is required"}');
|
||||
@@ -268,7 +266,7 @@ function enforceMasterKeyAccess(req, res, next) {
|
||||
next();
|
||||
}
|
||||
|
||||
function promiseEnforceMasterKeyAccess(request) {
|
||||
export function promiseEnforceMasterKeyAccess(request) {
|
||||
if (!request.auth.isMaster) {
|
||||
let error = new Error();
|
||||
error.status = 403;
|
||||
@@ -282,12 +280,3 @@ function invalidRequest(req, res) {
|
||||
res.status(403);
|
||||
res.end('{"error":"unauthorized"}');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
allowCrossDomain: allowCrossDomain,
|
||||
allowMethodOverride: allowMethodOverride,
|
||||
handleParseErrors: handleParseErrors,
|
||||
handleParseHeaders: handleParseHeaders,
|
||||
enforceMasterKeyAccess: enforceMasterKeyAccess,
|
||||
promiseEnforceMasterKeyAccess,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user