Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #1802, combine parent-helper.js and set-content-hosting-origin.js
Browse files Browse the repository at this point in the history
Make the scripts inclusion dependent on there being a full page/iframe
  • Loading branch information
ianb committed Nov 1, 2016
1 parent 3929f1e commit 6db660d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions server/src/pages/shot/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class Head extends React.Component {
<link rel="alternate" type="application/json+oembed" href={this.props.shot.oembedUrl} title={`${this.props.shot.title} oEmbed`} />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{this.socialMetadata()}
<script src={ this.props.staticLink("/set-content-hosting-origin.js") } />
<script src={ this.props.staticLink("/static/js/parent-helper.js") } />
{this.props.shot.showPage ? <script src={ this.props.staticLink("/parent-helper.js") } /> : null}
</reactruntime.HeadTemplate>);
}

Expand Down
7 changes: 5 additions & 2 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ console.warn = logFactory("warn");
console.error = logFactory("error");

const path = require('path');
const { readFileSync } = require('fs');
const Cookies = require("cookies");

const { Shot } = require("./servershot");
Expand Down Expand Up @@ -242,10 +243,12 @@ function sendGaActivation(req, res, hashPage) {
});
}

app.get("/set-content-hosting-origin.js", function (req, res) {
const parentHelperJs = readFileSync(path.join(__dirname, "/static/js/parent-helper.js"), {encoding: "UTF-8"});

app.get("/parent-helper.js", function (req, res) {
setCache(res);
let postMessageOrigin = `${req.protocol}://${req.config.contentOrigin}`;
let script = `var CONTENT_HOSTING_ORIGIN = "${postMessageOrigin}";`
let script = `${parentHelperJs}\nvar CONTENT_HOSTING_ORIGIN = "${postMessageOrigin}";`
jsResponse(res, script);
});

Expand Down

0 comments on commit 6db660d

Please sign in to comment.