fix baseURL for preview frame

This commit is contained in:
Cassie Tarakajian 2016-11-30 12:38:53 -05:00
parent fd26b3f77c
commit 5dd0220610
2 changed files with 10 additions and 0 deletions

View file

@ -143,6 +143,10 @@ class PreviewFrame extends React.Component {
const parser = new DOMParser(); const parser = new DOMParser();
const sketchDoc = parser.parseFromString(htmlFile, 'text/html'); const sketchDoc = parser.parseFromString(htmlFile, 'text/html');
const base = sketchDoc.createElement('base');
base.href = `${window.location.href}/`;
sketchDoc.head.appendChild(base);
this.resolvePathsForElementsWithAttribute('src', sketchDoc, resolvedFiles); this.resolvePathsForElementsWithAttribute('src', sketchDoc, resolvedFiles);
this.resolvePathsForElementsWithAttribute('href', sketchDoc, resolvedFiles); this.resolvePathsForElementsWithAttribute('href', sketchDoc, resolvedFiles);
// should also include background, data, poster, but these are used way less often // should also include background, data, poster, but these are used way less often

View file

@ -20,6 +20,12 @@ export function serveProject(req, res) {
jsdom.env(htmlFile, (err, window) => { jsdom.env(htmlFile, (err, window) => {
const sketchDoc = window.document; const sketchDoc = window.document;
const base = sketchDoc.createElement('base');
const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
base.href = `${fullUrl}/`;
sketchDoc.head.appendChild(base);
resolvePathsForElementsWithAttribute('src', sketchDoc, files); resolvePathsForElementsWithAttribute('src', sketchDoc, files);
resolvePathsForElementsWithAttribute('href', sketchDoc, files); resolvePathsForElementsWithAttribute('href', sketchDoc, files);
resolveScripts(sketchDoc, files); resolveScripts(sketchDoc, files);