parse-serverparse-dashboard

How to disable /files endpoints on parse-server


With the newly available community version of Parse server (https://github.com/parse-community/parse-server) there does not seem to be a configuration option to disable the /files endpoints which allow for file upload and hosting. I would very much like to disable this feature, and Cloud Code server-side hooks are not a good option (not currently supported in parse-dashboard, among other problems). What's the best way to disable these endpoints?


Solution

  • Using a little middleware works for me. Add this to your parse app config:

    {
      "middleware": "disableFilesMiddleware",
    }
    

    And then for your middleware module disableFilesMiddleware.js:

    module.exports = function( req , res , next ){
    
      if( req.path.substring( 0 , 12 ) === '/parse/files' ) {
        res.status(400).send({ code: 119 , message: 'files endpoints are disabled' }); 
        return;
      }
    
      next();
    };