Gozala/teleport

impelmenting module wrapping middleware

Closed this issue · 2 comments

Should implement some middleware for nodejs that can be used for serveing working dir and wrapping modules on the fly.

Writing middle-ware is pretty easy, example below highlights the details:

var when = require('q').when
,   catalog = require('teleport/catalog').Catalog(/*path to package defaults to cwd*/)

function teleport(request, response) {
  // Strips out `packages/` prefix and `.js` file extension to get a module id.
  var id = request.path.substr('packages/'.length, path.length - 3)
  var transport = when(catalog, function(catalog) {
    return catalog.module(id).transport
  })
  when(transport, function moduleWrapped(source) {
    response.write(String(source))
  })
}

no longer relevant