Skip to content

Feature/oembed support #1984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 7, 2014
Merged

Conversation

malditogeek
Copy link
Contributor

Hi @remy!

This is a first attempt to implement oEmbed support for JSBin. oEmbed allows you to embed rich content without running arbitrary code (unlike the current embed method) and therefore is the prefer method for a lot of people including Gitter, here some more info: http://oembed.com/ and some examples: https://embed.spotify.com/oembed/?url=http://open.spotify.com/track/4fyHcNgv4PizcRMXUGPFQ2

Here's how they would look:

What do you think?

oembed.embed = function(req, res) {
var url = req.query.url;

if (!url || !url.match(/https?:\/\/jsbin.com/)) return res.send(400);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsbin.com shouldn't be hard coded here, I guess we're saying you can't embed the root (or non-bin documents).

But there is a helper to get this. @allouis is digging it out...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this piece of code to check that the url they're requesting is an actual jsbin url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allouis yes, exactly, if there's a helper to validate jsbin URL format would be great 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malditogeek We haven't got a helper to validate, but to ensure this runs just as well on local installs could you check against app.get('url host') this will return "jsbin.com" or "localhost:3000" etc...

@remy
Copy link
Member

remy commented Oct 7, 2014

This is awesome, thank you. There's a couple of tweaks required (inline comments), but if you can get this changed today/this morning, I'll merge it in today.

oembed.embed = function(req, res) {
var url = req.query.url;

if (!url || !url.match(config.url.host)) { return res.send(400); }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allouis I've seen that config is being used in the bin.js handler and has a url attribute, looks better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config is actually loaded on to app.settings, and since app is available on every request object, you don't need the require. So the coe is just .match(req.app.settings.url.host) and one less require (which actually does count towards boot time!)

@remy remy merged commit a6f6ece into jsbin:master Oct 7, 2014
@remy
Copy link
Member

remy commented Oct 7, 2014

Going live shortly! (though, it's 5pm which is past the deadly hour, but WE CAN DO IT!)

@malditogeek
Copy link
Contributor Author

Sweet! Thanks for your help guys! :shipit:

@remy
Copy link
Member

remy commented Oct 7, 2014

Live.

Though, shouldn't there be a meta tag in the header say what the embed url is?

@malditogeek
Copy link
Contributor Author

Awesome, dat continuous deployment :D

It's optional, it's used for auto-discovery but will add it
tonight/tomorrow and send you a PR.

Cheers!

On Tue, Oct 7, 2014 at 6:08 PM, Remy Sharp notifications@github.com wrote:

Live.

Though, shouldn't there be a meta tag in the header say what the embed url
is?


Reply to this email directly or view it on GitHub
#1984 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants