Skip to content

⚡ adds ability to run the dashboard from any mount point #217

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

Merged
merged 4 commits into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ packageJson('parse-dashboard', 'latest').then(latestPackage => {
}
});

module.exports = function(config) {
function getMount(req) {
let url = req.url;
let originalUrl = req.originalUrl;
var mountPathLength = req.originalUrl.length - req.url.length;
var mountPath = req.originalUrl.slice(0, mountPathLength);
if (!mountPath.endsWith('/')) {
mountPath += '/';
}
return mountPath;
}

module.exports = function(config, allowInsecureHTTP) {
var app = express();
// Serve public files.
app.use(express.static(path.join(__dirname,'public')));
Expand Down Expand Up @@ -83,7 +94,22 @@ module.exports = function(config) {

// For every other request, go to index.html. Let client-side handle the rest.
app.get('/*', function(req, res) {
res.sendFile(__dirname + '/index.html');
let mountPath = getMount(req);
res.send(`<!DOCTYPE html>
<head>
<base href="${mountPath}"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needed to properly route the request

<script>
PARSE_DASHBOARD_PATH = "${mountPath}";
</script>
</head>
<html>
<title>Parse Dashboard</title>
<body>
<div id="browser_mount"></div>
<script src="${mountPath}bundles/dashboard.bundle.js"></script>
</body>
</html>
`);
});

return app;
Expand Down
8 changes: 0 additions & 8 deletions Parse-Dashboard/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion Parse-Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ p.then(config => {

const app = express();

app.use(parseDashboard(config.data));
app.use(parseDashboard(config.data, allowInsecureHTTP));
// Start the server.
app.listen(port);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"build": "NODE_ENV=production webpack --config webpack/production.config.js && webpack --config webpack/PIG.config.js",
"test": "NODE_PATH=./node_modules jest",
"generate": "node scripts/generate.js",
"prepublish": "webpack --config webpack/publish.config.js --progress",
"prepublish": "webpack --config webpack/publish.config.js",
"start": "node ./Parse-Dashboard/index.js"
},
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let Icon = ({ name, fill, width, height }) => {
}
return (
<svg {...props} >
<use xlinkHref={`/bundles/sprites.svg#${name}`} />
<use xlinkHref={`bundles/sprites.svg#${name}`} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no / as it should be relative to base

</svg>
);
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/PushPreview/PushPreview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

.ios {
background-image: url(/images/iphone.jpg);
background-image: url(components/PushPreview/iphone.jpg);
background-size: 325px auto;
font-family: '.SFNSDisplay-Regular', 'Helvetica Neue', 'Lucida Grande', sans-serif;
color: white;
Expand Down Expand Up @@ -159,7 +159,7 @@
}

.android {
background-image: url(/images/android.jpg);
background-image: url(components/PushPreview/android.jpg);
background-size: 325px auto;
font-family: 'Roboto', 'Helvetica Neue', 'Arial', sans-serif;

Expand Down Expand Up @@ -229,7 +229,7 @@
}

.osx {
background-image: url(/images/laptop.jpg);
background-image: url(components/PushPreview/laptop.jpg);
background-size: 325px auto;
font-family: '.SFNSDisplay-Regular', 'Helvetica Neue', 'Lucida Grande', sans-serif;
color: #555252;
Expand Down Expand Up @@ -272,7 +272,7 @@
}

.windows {
background-image: url(/images/windowsphone.jpg);
background-image: url(components/PushPreview/windowsphone.jpg);
background-size: 325px auto;
font-family: 'Arial', sans-serif;
color: white;
Expand Down
3 changes: 2 additions & 1 deletion src/dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Webhooks from './Data/Webhooks/Webhooks.react';
import { AsyncStatus } from 'lib/Constants';
import { center } from 'stylesheets/base.scss';
import { get } from 'lib/AJAX';
import { setBasePath } from 'lib/AJAX';
import {
Router,
Route,
Expand Down Expand Up @@ -108,12 +109,12 @@ const PARSE_DOT_COM_SERVER_INFO = {
class Dashboard extends React.Component {
constructor(props) {
super();

this.state = {
configLoadingError: '',
configLoadingState: AsyncStatus.PROGRESS,
newFeaturesInLatestVersion: [],
};
setBasePath(props.path);
}

componentDidMount() {
Expand Down
3 changes: 2 additions & 1 deletion src/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ import 'babel-polyfill';
require('stylesheets/fonts.scss');
installDevTools(Immutable);

ReactDOM.render(<Dashboard/>, document.getElementById('browser_mount'));
var path = window.PARSE_DASHBOARD_PATH || '/';
ReactDOM.render(<Dashboard path={path}/>, document.getElementById('browser_mount'));
14 changes: 14 additions & 0 deletions src/lib/AJAX.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ import * as CSRFManager from 'lib/CSRFManager';
import encodeFormData from 'lib/encodeFormData';
import { Promise } from 'parse';

let basePath = '';
export function setBasePath(newBasePath) {
basePath = newBasePath || '';
if (basePath.endsWith('/')) {
basePath = basePath.slice(0, basePath.length-1);
}
}

// abortable flag used to pass xhr reference so user can abort accordingly
export function request(method, url, body, abortable = false, withCredentials = true, useRequestedWith = true) {
if (!url.startsWith('http://')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

open to suggestions about that, that's the less invasive I've found

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this is fine. The only things that aren't going to go through the Parse sdk are the config loading, and potentially this app creation stuff that is being discussed.

&& !url.startsWith('https://')
&& basePath.length
&& !url.startsWith(basePath)) {
url = basePath + url;
}
let xhr = new XMLHttpRequest();
xhr.open(method, url, true);
if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
Expand Down
5 changes: 4 additions & 1 deletion webpack/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
context: path.join(__dirname, '../src'),
output: {
filename: '[name].bundle.js',
publicPath: '/bundles/'
publicPath: 'bundles/'
},
resolve: {
root: [__dirname,path.join(__dirname, '../src'), path.join(__dirname, 'node_modules')]
Expand All @@ -41,6 +41,9 @@ module.exports = {
}, {
test: /\.png$/,
loader: 'file-loader?name=img/[hash].[ext]',
}, {
test: /\.jpg$/,
loader: 'file-loader?name=img/[hash].[ext]',
}
]
},
Expand Down