Skip to content

Commit 7a7185f

Browse files
committed
⚡ passes path to Dashboard component for AJAX
1 parent 4f92208 commit 7a7185f

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

Parse-Dashboard/app.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ packageJson('parse-dashboard', 'latest').then(latestPackage => {
1515
}
1616
});
1717

18+
function getMount(req) {
19+
let url = req.url;
20+
let originalUrl = req.originalUrl;
21+
var mountPathLength = req.originalUrl.length - req.url.length;
22+
var mountPath = req.originalUrl.slice(0, mountPathLength);
23+
if (!mountPath.endsWith('/')) {
24+
mountPath += '/';
25+
}
26+
return mountPath;
27+
}
28+
1829
module.exports = function(config, allowInsecureHTTP) {
1930
var app = express();
2031
// Serve public files.
@@ -83,18 +94,12 @@ module.exports = function(config, allowInsecureHTTP) {
8394

8495
// For every other request, go to index.html. Let client-side handle the rest.
8596
app.get('/*', function(req, res) {
86-
let url = req.url;
87-
let originalUrl = req.originalUrl;
88-
var mountPathLength = req.originalUrl.length - req.url.length;
89-
var mountPath = req.originalUrl.slice(0, mountPathLength);
90-
if (!mountPath.endsWith('/')) {
91-
mountPath += '/';
92-
}
97+
let mountPath = getMount(req);
9398
res.send(`<!DOCTYPE html>
9499
<head>
95100
<base href="${mountPath}"/>
96101
<script>
97-
PARSE_DASHBOARD_CONFIG_URI = "${mountPath}parse-dashboard-config.json";
102+
PARSE_DASHBOARD_PATH = "${mountPath}";
98103
</script>
99104
</head>
100105
<html>

Parse-Dashboard/index.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/dashboard/Dashboard.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import Webhooks from './Data/Webhooks/Webhooks.react';
4848
import { AsyncStatus } from 'lib/Constants';
4949
import { center } from 'stylesheets/base.scss';
5050
import { get } from 'lib/AJAX';
51+
import { setBasePath } from 'lib/AJAX';
5152
import {
5253
Router,
5354
Route,
@@ -113,10 +114,11 @@ class Dashboard extends React.Component {
113114
configLoadingState: AsyncStatus.PROGRESS,
114115
newFeaturesInLatestVersion: [],
115116
};
117+
setBasePath(props.path);
116118
}
117119

118120
componentDidMount() {
119-
get(this.props.configURI).then(({ apps, newFeaturesInLatestVersion = [] }) => {
121+
get('/parse-dashboard-config.json').then(({ apps, newFeaturesInLatestVersion = [] }) => {
120122
this.setState({ newFeaturesInLatestVersion });
121123
let appInfoPromises = apps.map(app => {
122124
if (app.serverURL.startsWith('https://api.parse.com/1')) {

src/dashboard/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ import 'babel-polyfill';
1717
require('stylesheets/fonts.scss');
1818
installDevTools(Immutable);
1919

20-
var configURI = window.PARSE_DASHBOARD_CONFIG_URI || '/parse-dashboard-config.json';
21-
ReactDOM.render(<Dashboard configURI={configURI}/>, document.getElementById('browser_mount'));
20+
var path = window.PARSE_DASHBOARD_PATH || '/';
21+
ReactDOM.render(<Dashboard path={path}/>, document.getElementById('browser_mount'));

src/lib/AJAX.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,22 @@ import * as CSRFManager from 'lib/CSRFManager';
99
import encodeFormData from 'lib/encodeFormData';
1010
import { Promise } from 'parse';
1111

12+
let basePath = '';
13+
export function setBasePath(newBasePath) {
14+
basePath = newBasePath || '';
15+
if (basePath.endsWith('/')) {
16+
basePath = basePath.slice(0, basePath.length-1);
17+
}
18+
}
19+
1220
// abortable flag used to pass xhr reference so user can abort accordingly
1321
export function request(method, url, body, abortable = false, withCredentials = true, useRequestedWith = true) {
22+
if (!url.startsWith('http://')
23+
&& !url.startsWith('https://')
24+
&& basePath.length
25+
&& !url.startsWith(basePath)) {
26+
url = basePath + url;
27+
}
1428
let xhr = new XMLHttpRequest();
1529
xhr.open(method, url, true);
1630
if (method === 'POST' || method === 'PUT' || method === 'DELETE') {

0 commit comments

Comments
 (0)