Skip to content

Commit 2a03d69

Browse files
flovilmartdrew-gross
authored andcommitted
⚡ adds ability to run the dashboard from any mount point
* ⚡ adds ability to run the dashboard from any mount point - fixes allowInsecureHTTP * PushPreview images part of the build system * ⚡ passes path to Dashboard component for AJAX * removes --progres on prepublish that break heroku builds
1 parent fb0726b commit 2a03d69

File tree

14 files changed

+57
-20
lines changed

14 files changed

+57
-20
lines changed

Parse-Dashboard/app.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@ packageJson('parse-dashboard', 'latest').then(latestPackage => {
1515
}
1616
});
1717

18-
module.exports = function(config) {
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+
29+
module.exports = function(config, allowInsecureHTTP) {
1930
var app = express();
2031
// Serve public files.
2132
app.use(express.static(path.join(__dirname,'public')));
@@ -83,7 +94,22 @@ module.exports = function(config) {
8394

8495
// For every other request, go to index.html. Let client-side handle the rest.
8596
app.get('/*', function(req, res) {
86-
res.sendFile(__dirname + '/index.html');
97+
let mountPath = getMount(req);
98+
res.send(`<!DOCTYPE html>
99+
<head>
100+
<base href="${mountPath}"/>
101+
<script>
102+
PARSE_DASHBOARD_PATH = "${mountPath}";
103+
</script>
104+
</head>
105+
<html>
106+
<title>Parse Dashboard</title>
107+
<body>
108+
<div id="browser_mount"></div>
109+
<script src="${mountPath}bundles/dashboard.bundle.js"></script>
110+
</body>
111+
</html>
112+
`);
87113
});
88114

89115
return app;

Parse-Dashboard/index.html

-8
This file was deleted.

Parse-Dashboard/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ p.then(config => {
9191

9292
const app = express();
9393

94-
app.use(parseDashboard(config.data));
94+
app.use(parseDashboard(config.data, allowInsecureHTTP));
9595
// Start the server.
9696
app.listen(port);
9797

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"build": "NODE_ENV=production webpack --config webpack/production.config.js && webpack --config webpack/PIG.config.js",
7373
"test": "NODE_PATH=./node_modules jest",
7474
"generate": "node scripts/generate.js",
75-
"prepublish": "webpack --config webpack/publish.config.js --progress",
75+
"prepublish": "webpack --config webpack/publish.config.js",
7676
"start": "node ./Parse-Dashboard/index.js"
7777
},
7878
"bin": {

src/components/Icon/Icon.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let Icon = ({ name, fill, width, height }) => {
1818
}
1919
return (
2020
<svg {...props} >
21-
<use xlinkHref={`/bundles/sprites.svg#${name}`} />
21+
<use xlinkHref={`bundles/sprites.svg#${name}`} />
2222
</svg>
2323
);
2424
};

src/components/PushPreview/PushPreview.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
}
9494

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

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

@@ -229,7 +229,7 @@
229229
}
230230

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

274274
.windows {
275-
background-image: url(/images/windowsphone.jpg);
275+
background-image: url(components/PushPreview/windowsphone.jpg);
276276
background-size: 325px auto;
277277
font-family: 'Arial', sans-serif;
278278
color: white;

src/dashboard/Dashboard.js

+2-1
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,
@@ -108,12 +109,12 @@ const PARSE_DOT_COM_SERVER_INFO = {
108109
class Dashboard extends React.Component {
109110
constructor(props) {
110111
super();
111-
112112
this.state = {
113113
configLoadingError: '',
114114
configLoadingState: AsyncStatus.PROGRESS,
115115
newFeaturesInLatestVersion: [],
116116
};
117+
setBasePath(props.path);
117118
}
118119

119120
componentDidMount() {

src/dashboard/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ import 'babel-polyfill';
1717
require('stylesheets/fonts.scss');
1818
installDevTools(Immutable);
1919

20-
ReactDOM.render(<Dashboard/>, 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

+14
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') {

webpack/base.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
context: path.join(__dirname, '../src'),
1515
output: {
1616
filename: '[name].bundle.js',
17-
publicPath: '/bundles/'
17+
publicPath: 'bundles/'
1818
},
1919
resolve: {
2020
root: [__dirname,path.join(__dirname, '../src'), path.join(__dirname, 'node_modules')]
@@ -41,6 +41,9 @@ module.exports = {
4141
}, {
4242
test: /\.png$/,
4343
loader: 'file-loader?name=img/[hash].[ext]',
44+
}, {
45+
test: /\.jpg$/,
46+
loader: 'file-loader?name=img/[hash].[ext]',
4447
}
4548
]
4649
},

0 commit comments

Comments
 (0)