diff --git a/client/modules/IDE/components/PreviewFrame.jsx b/client/modules/IDE/components/PreviewFrame.jsx index a13b0cb6..6533caca 100644 --- a/client/modules/IDE/components/PreviewFrame.jsx +++ b/client/modules/IDE/components/PreviewFrame.jsx @@ -143,6 +143,10 @@ class PreviewFrame extends React.Component { const parser = new DOMParser(); 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('href', sketchDoc, resolvedFiles); // should also include background, data, poster, but these are used way less often diff --git a/server/controllers/embed.controller.js b/server/controllers/embed.controller.js index 069cb88f..5d73b71f 100644 --- a/server/controllers/embed.controller.js +++ b/server/controllers/embed.controller.js @@ -20,6 +20,12 @@ export function serveProject(req, res) { jsdom.env(htmlFile, (err, window) => { 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('href', sketchDoc, files); resolveScripts(sketchDoc, files);