parse-dashboard icon indicating copy to clipboard operation
parse-dashboard copied to clipboard

Custom FileAdapter breaks dashboard

Open W0lfw00d opened this issue 4 years ago • 4 comments

When adding a custom FileAdapter (works as expected) in parse-server it generated a server error in the dashboard.

"TypeError: Converting circular structure to JSON"

This seems to be the reason: image

Environment Setup

node 13.0.1 npm 6.13.1 parse-dashboard 2.0.5 parse-server 4.2.0

Steps to reproduce

Add a custom fileAdapter that uses mongodb client to parse-server.

The most basic example: ImageGridFSBucketAdapter.js

const { GridFSBucketAdapter } = require('parse-server/lib/Adapters/Files/GridFSBucketAdapter');

module.exports = class ImageGridFSBucketAdapter extends GridFSBucketAdapter {
  constructor(mongoDatabaseURI, mongoOptions = {}) {
    super(mongoDatabaseURI, mongoOptions);
  }
};

Where you start the parse-server:

const ImageGridFSBucketAdapter = require('./adapters/ImageGridFSBucketAdapter');
  const config = {
    ...
    filesAdapter: new ImageGridFSBucketAdapter(config.databaseURI),
    ...
  };

  const parse = ParseServer.start(config, async () => {
    ...
  });

(the same thing happens when you just copy the GridFSBucketAdapter instead of extending it)

Than load the dashboard, upload file using the dashboard (or your api) and refresh the dashboard.

Logs/Trace

Note: If you get a browser JS error please run npm run dev. This will provide source maps and a much more useful stack trace. In the parse-server log and in the network request for http://localhost:1337/dashboard/parse-dashboard-config.json

TypeError: Converting circular structure to JSON --> starting at object with constructor 'NativeTopology' | property 's' -> object with constructor 'Object' | property 'sessionPool' -> object with constructor 'ServerSessionPool' --- property 'topology' closes the circle at JSON.stringify () at stringify (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/response.js:1123:12) at ServerResponse.json (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/response.js:260:14) at /Users/wolfwood/dev/project-name/packages/apps/api/node_modules/parse-dashboard/Parse-Dashboard/app.js:133:20 at Layer.handle [as handle_request] (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/layer.js:95:5) at next (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/layer.js:95:5) at /Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:335:12) at next (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:275:10) at Layer.handle [as handle_request] (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/layer.js:91:12) at trim_prefix (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:317:13) at /Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:335:12) at next (/Users/wolfwood/dev/project-name/packages/apps/api/node_modules/express/lib/router/index.js:275:10)

W0lfw00d avatar Apr 09 '20 12:04 W0lfw00d

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 24 '20 13:05 stale[bot]

Closing an issue because it's 'stale' seems shady, but whatever.

camdagr8 avatar Dec 21 '20 23:12 camdagr8

We ran into pretty much this exact same issue with a custom FilesAdapter. I think you can get this error to go away by just omitting the filesAdapter property when you instantiate the ParseDashboard. Node/Express doesn't like serializing circular references in json responses.

We were reusing the Parse server config to also be the base configuration for the parse dashboard, but this meant that the config.filesAdapter that was being passed to the parse server was also passed on to the dashboard.

I slimmed this down just just an important handful of properties that were shared between them:

        const {
            appId,
            appName,
            masterKey,
            sessionLength,
            serverURL,
            publicServerURL,
        } = parseConfig();

        const dashboardConfig = {
            trustProxy: 1,
            users: ENV.PARSE_DASHBOARD_USERS,
            apps: [
                {
                    appId,
                    appName,
                    masterKey,
                    sessionLength,
                    serverURL,
                    publicServerURL,
                },
            ],
        };

        const dashboard = new ParseDashboard(dashboardConfig, {
            allowInsecureHTTP: ENV.PARSE_DASHBOARD_ALLOW_INSECURE_HTTP,
        });

        app.use(ENV.PARSE_DASHBOARD_MOUNT, dashboard);

The long term fix for the /parse-dashboard-config.json could be to explicitly filter out properties the dashboard doesn't need and doesn't use.

    // Serve the configuration.
    app.get('/parse-dashboard-config.json', function(req, res) {
      let apps = config.apps.map((app) => copySanitizeApp(app)); // do something here to clean up configuration
...

jdillick avatar Dec 22 '20 21:12 jdillick

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 09 '21 03:06 stale[bot]