Merge pull request #1875 from chrisgarrity/issue/fix-path-for-fastly

Correct preview route for fastly
This commit is contained in:
chrisgarrity 2018-05-03 08:14:48 -04:00 committed by GitHub
commit 1cfc5a8144
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 23 deletions

View file

@ -176,7 +176,7 @@ async.auto({
if (err) throw new Error(err);
if (process.env.FASTLY_ACTIVATE_CHANGES) {
fastly.activateVersion(results.version, function (e, resp) {
if (err) throw new Error(e);
if (e) throw new Error(e);
process.stdout.write('Successfully configured and activated version ' + resp.number + '\n');
if (process.env.FASTLY_PURGE_ALL) {
fastly.purgeAll(FASTLY_SERVICE_ID, function (error) {

View file

@ -193,7 +193,7 @@
},
{
"name": "preview",
"pattern": "^/preview/(*)/?$",
"pattern": "^/preview(/editor|(/\\d+(/editor|/fullscreen)?)?)?/?$",
"routeAlias": "/preview/?$",
"view": "preview/preview",
"title": "Scratch 3.0 Preview"

View file

@ -54,31 +54,19 @@ class Preview extends React.Component {
}
}
initState () {
let pathname = window.location.pathname.toLowerCase();
const params = {
const pathname = window.location.pathname.toLowerCase();
const parts = pathname.split('/').filter(Boolean);
// parts[0]: 'preview'
// parts[1]: either :id or 'editor'
// parts[2]: undefined if no :id, otherwise either 'editor' or 'fullscreen'
return {
editable: false,
favoriteCount: 0,
inEditor: false,
isFullScreen: false,
inEditor: parts.indexOf('editor') !== -1,
isFullScreen: parts.indexOf('fullscreen') !== -1,
loveCount: 0,
projectId: null
projectId: parts[1] === 'editor' ? null : parts[1]
};
if (pathname[pathname.length - 1] === '/') {
pathname = pathname.substring(0, pathname.length - 1);
}
const path = pathname.split('/');
if (path[path.length - 1] === 'editor' || path[path.length - 1] === 'preview') {
params.inEditor = true;
path.pop();
}
if (path[path.length - 1] === 'fullscreen') {
params.isFullScreen = true;
path.pop();
}
if (/^\d+$/.test(path[path.length - 1])) {
params.projectId = path.pop();
}
return params;
}
handleFavoriteToggle () {
this.props.setFavedStatus(