Skip to content

Adds support for using Parse Dashboard as Express middleware #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Conversation

leonluc-dev
Copy link

Added support for using Parse Dashboard as a Express middleware.
Based on Parse Server middleware.

Project structure changes:

-Wrapped Parse Dashboard code in a ParseDashboard class in
Parse-Dashboard\index.js
-Moved CLI/NPM invoked code to Parse-Dashboard\cli\index.js

Added support for using Parse Dashboard as a Express middleware.

Project structure changes:

-Moved general Parse Dashboard code to a ParseDashboard class in
Parse-Dashboard\index.js
-Moved CLI/NPM invoked code to Parse-Dashboard\cli\index.js
-Made index.js main file of module
@facebook-github-bot
Copy link

By analyzing the blame information on this pull request, we identified @drew-gross, @gimdongwoo and @flovilmart to be potential reviewers.

@facebook-github-bot
Copy link

@Gameleon12 updated the pull request.

@leonluc-dev
Copy link
Author

Just now discovered a bug in the current implementation of this issue.

Since all urls for assets in the html and react.js scripts are defined as relative to the root of the server (a.k.a. /), Parse Dashboard will mount but will not load if it is mounted on any other endpoint than /

I will look into fixing this.

@mamaso
Copy link

mamaso commented Mar 31, 2016

Extremely interested in this enhancement as well.

If it helps, I mounted the parse dashboard off the /parse-dashboard/ route in this commit: mamaso@8821cbf

Relevant changes were setting <base href="/parse-dashboard/" /> in index.html and changing most /apps/ and /bundles/ root-relative urls in src and webpack to fully relative urls

@drew-gross drew-gross closed this in 75d740f Apr 1, 2016
@drew-gross drew-gross reopened this Apr 1, 2016
georgeloh added a commit to georgeloh/parse-dashboard that referenced this pull request Apr 1, 2016
@leonluc-dev
Copy link
Author

@mamaso Thanks for referencing that commit. It is indeed a very helpful pointer in the right direction.

The problem with it's current form is that the relative uri's stack up on top of each other while navigating through Parse Dashboard (leading to paths such as /apps/MyApps/apps/MyApps/browser/apps/MyApps/browser/_Installation/apps/MyApps/browser/apps/MyApps/browser/MyCustomClass).

It seems the way to go is to prefix all the uri's in the react.js files with where the Express application has mounted parse-dashboard relative to the root. I am not very proficient with React so any tips, tricks, commits etc. to help and speed things up while I'm working on this would be very welcome.

@flovilmart
Copy link
Contributor

I'm not sure you need all those changes.

You just need to implement in your middleware a way to:

  1. serve parse-dashboard-config.json
  2. redirect all requests to index.html

So if there is 1 thing to do, it's maybe just extract the handler for GET /parse-dashboard-config.json

@mamaso
Copy link

mamaso commented Apr 1, 2016

@flovilmart Redirecting all requests to index.html doesn't quite solve the issue. Because all the react urls are root relative and will strip the mount path, how can you detect whether they are actually intended for the root or for whatever path the parse dashboard is mounted on?

@Gameleon12 Interesting, not the biggest expert on react either. Did you set <base href="/parse-dashboard/" />? See this for more info, useBasename in react seems like the solution they've created for this: remix-run/react-router#2014

@flovilmart
Copy link
Contributor

@mamaso So that's even better, that allows you to do

app.use('/parse-dashboard/*, (req, res) => {
   res.sendFile(__dirname + '/index.html');
});

program.option('--config [config]', 'the path to the configuration file');
program.option('--port [port]', 'the port to run parse-dashboard');
program.option('--allowInsecureHTTP [allowInsecureHTTP]', 'set this flag when you are running the dashboard behind an HTTPS load balancer or proxy with early SSL termination.');
class ParseDashboard {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work as we don't pass it through babel AFAIK

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code doesn't pass through babel, but Node.js supports some features of ECMAScript 6 (including classes, albeit only in strict mode) without the need for babel compilation. (See: https://nodejs.org/en/docs/es6/)

@mamaso
Copy link

mamaso commented Apr 1, 2016

@flovilmart Just played around a bit and I think you're right, looks like when I did this I went a wee bit overboard on the relative urls. Here's what I think are necessary changes:

@flovilmart
Copy link
Contributor

I'm working on something that just does that

@leonluc-dev
Copy link
Author

@flovilmart

I'm not sure you need all those changes.

You just need to implement in your middleware a way to:

serve parse-dashboard-config.json
redirect all requests to index.html

So if there is 1 thing to do, it's maybe just extract the handler for GET /parse-dashboard-config.json

While splitting off the general dashboard and cli related code isn't a necessity to add middleware support, it does make the code a bit cleaner to maintain and use. In addition, initialization of Parse Dashboard as middleware in this way is consistent with how Parse Server is initialized as middleware.

But I suppose using a non class based node module exports implementation would work just fine too.

@flovilmart
Copy link
Contributor

see #214.

Now I need to find a way to properly set , either by temptlates or just a pure regex

@drew-gross
Copy link
Contributor

Superseded by #214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants