Skip to content

Commit

Permalink
fix: correct oembed frame source (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
smeijer committed Oct 30, 2020
1 parent ea397df commit d3f0fc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/lambda/oembed/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function handler(event, context, callback) {
}

const { url, referrer, maxwidth = 900, maxheight = 300 } = params;
const iframeSrc = `${url.replace('gist', 'embed')}?panes=preview,result`;

callback(null, {
statusCode: 200,
Expand All @@ -48,7 +47,7 @@ function handler(event, context, callback) {
provider_name: 'testing-playground.com',
provider_url: host,

html: `<iframe src="${iframeSrc}" height="${maxheight}" width="${maxwidth}" scrolling="no" frameBorder="0" allowTransparency="true" title="Testing Playground" style="overflow: hidden; display: block; width: 100%"></iframe>`,
html: `<iframe src="${url}" height="${maxheight}" width="${maxwidth}" scrolling="no" frameBorder="0" allowTransparency="true" title="Testing Playground" style="overflow: hidden; display: block; width: 100%"></iframe>`,
width: maxwidth,
height: maxheight,

Expand Down
10 changes: 8 additions & 2 deletions src/lambda/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const path = require('path');
const queryString = require('query-string');

const filename = path.join(__dirname, './index.html');
const indexHtml = fs.readFileSync(filename, 'utf8');
const indexHtml = fs.existsSync(filename)
? fs.readFileSync(filename, 'utf8')
: fs.readFileSync(
path.join(__dirname, '../../../dist/client/index.html'),
'utf8',
);

function getHostname(event, context) {
if (event.headers.host) {
Expand All @@ -19,7 +24,8 @@ function handler(event, context, callback) {
const { panes, markup, query } = event.queryStringParameters;
const host = getHostname(event, context);

const frameSrc = `${host}/embed?${queryString.stringify({
const embedPath = event.path.replace('/gist/', '/embed/');
const frameSrc = `${host}${embedPath}?${queryString.stringify({
panes,
markup,
query,
Expand Down

0 comments on commit d3f0fc8

Please sign in to comment.