Skip to content

Commit

Permalink
fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hayes committed May 14, 2014
1 parent b95c7ab commit 52280c4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"auth" : {
"authenticated_gets": false,
"whitelist": ["/_session", "/-/user/org.couchdb.user:*"]
}
},
"fallback": false
}
12 changes: 11 additions & 1 deletion lib/controllers/get_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function get_package(context, route, respond) {
}

if(!meta) {
return respond.not_found()
return not_found()
}

if(!version) {
Expand All @@ -44,4 +44,14 @@ function get_package(context, route, respond) {
return base_url + '/' + name + '/-/' + name + '-' + version + '.tgz'
}

function not_found() {
if(!context.config.fallback) {
return respond.not_found()
}

context.res.writeHead(302, {
Location: context.config.fallback + context.route.path
})
context.res.end()
}
}
19 changes: 0 additions & 19 deletions lib/models/Package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var guard = require('../utils/guard')
, context = require('../context')
, request = require('request')
, semver = require('semver')
, path = require('path')
, Package = {}
Expand All @@ -12,7 +11,6 @@ Package.removeVersion = remove_version
Package.getVersions = get_versions
Package.publish = publish
Package.remove = remove
Package.add = add

var methods = [
'getMeta'
Expand Down Expand Up @@ -202,20 +200,3 @@ function save_meta(name, version, tags, meta, done) {
})
})
}

function add(name, version, tags, meta, tarball, done) {
var req

try {
req = request(tarball)
req.pipe(Package.setTarball(name, version))
req.on('error', function(err) {
done(err)
})
req.on('end', function() {
save_meta(name, version, tags, meta, done)
})
} catch(err) {
done(err)
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
"concat-stream": "1.4.1",
"mkdirp": "0.3.5",
"password-hash": "1.2.1",
"request": "2.33.0",
"semver": "2.2.1",
"nopt": "2.2.0",
"unpm-router": "0.0.3",
"unpm-router": "0.0.4",
"continuation-local-storage": "3.0.0",
"unpm-fs-backend": "0.0.7",
"unpm-auth": "0.1.3",
Expand All @@ -34,7 +33,8 @@
"coveralls": "2.8.0",
"mocha-lcov-reporter": "0.0.1",
"unpm-mem-backend": "0.4.1",
"jsl": "0.1.1"
"jsl": "0.1.1",
"request": "^2.34.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 52280c4

Please sign in to comment.