Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
oEmbed provider middleware for Node.js Connect and Express
tag: 0.0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.npmignore
.travis.yml
README.md
example.js
index.js
package.json

README.md

connect-oembed

oEmbed provider middleware for Node.js Connect and Express. Adds support to Connect/Express for creating an oEmbed provider API (ie http://example.com/oembed).

Build Status

Installation

connect-oembed is available via npm:

npm install connect-oembed

Usage

var connect = require('connect');
var oembed = require('connect-oembed');

var app = connect();

app.use('/oembed', oembed(function(req, res, next) {
  // determine your embed details here based on query params in req.oembed

  // say we're oembedding images from http://example.com/images/<image id>
  var urlRegEx = /^http:\/\/example\.com\/images\/([0-9]+)/;
  var matched = urlRegEx.exec(req.oembed.url);
  if (matched != null) {
    var imageId = matched[1];

    // here you could look up some meta from a database, for now we can just
    // return some made up values using the res.oembed.photo() helper
    res.oembed.photo(
      "http://static.example.com/resources/images/" + imageId, // url
      256,  // width
      256); // height

    // the helper automatically builds and sends the response for you
    // so there's nothing left to do here
  }
  else
    next();
}));

app.listen(8080);
Something went wrong with that request. Please try again.