parse-dashboard
parse-dashboard copied to clipboard
Custom FileAdapter breaks dashboard
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:
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 (
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.
Closing an issue because it's 'stale' seems shady, but whatever.
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
...
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.