From 5dd0220610809568b51642e202e8228c3faeffd2 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 30 Nov 2016 12:38:53 -0500 Subject: [PATCH] fix baseURL for preview frame --- client/modules/IDE/components/PreviewFrame.jsx | 4 ++++ server/controllers/embed.controller.js | 6 ++++++ 2 files changed, 10 insertions(+) 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);