Skip to content

Commit

Permalink
allow attachments to be an http endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Mar 11, 2012
1 parent ee8e069 commit f12ff71
Show file tree
Hide file tree
Showing 461 changed files with 87,467 additions and 59 deletions.
25 changes: 17 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = function (t, rewrites, options) {
return to
}

function createProxy(req, resp, opts, stream) {
var proxy = request(opts)
function createProxy(req, resp, proxyOpts, stream) {
var proxy = request(proxyOpts)
req.pipe(proxy)
if (stream) {
stream.pipe(proxy)
Expand All @@ -52,9 +52,18 @@ module.exports = function (t, rewrites, options) {
})
}

function proxyFile(rewrite, req, resp) {
function proxyFile(rewrite) {
route(rewrite, function(req, resp) {
filed(path.resolve(opts.attachments, rewrite.to)).pipe(resp)
var files = opts.attachments
if (!files) {
resp.statusCode = 404
return resp.end('not found')
}
if (_.isString(files) && files.match(/https?/i)) {
var to = opts.attachments + '/' + rewrite.to
return createProxy(req, resp, to)
}
filed(path.resolve(files, rewrite.to)).pipe(resp)
})
}

Expand All @@ -69,9 +78,9 @@ module.exports = function (t, rewrites, options) {
if (query.startkey) query.startkey = JSON.stringify(query.startkey)
if (query.endkey) query.endkey = JSON.stringify(query.endkey)
if (_.keys(query).length) to += "?" + qs.stringify(query)
var opts = {url: to}
if (rewrite.json) opts.json = rewrite.json
createProxy(req, resp, opts, stream)
var proxyOpts = {url: to}
if (rewrite.json) proxyOpts.json = rewrite.json
createProxy(req, resp, proxyOpts, stream)
})
}

Expand Down Expand Up @@ -105,6 +114,6 @@ module.exports = function (t, rewrites, options) {
else return proxyFile(rewrite)
})

t.route('/*').files(opts.attachments)
if (opts.attachments) t.route('/*').files(opts.attachments)
}

24 changes: 14 additions & 10 deletions node_modules/filed/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/filed/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions node_modules/socket.io/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/socket.io/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

218 changes: 218 additions & 0 deletions node_modules/socket.io/History.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions node_modules/socket.io/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f12ff71

Please sign in to comment.