Skip to content

Commit

Permalink
Try to find packages in alternative locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jun 5, 2024
1 parent bc2a030 commit 670f855
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ app.use(function(err, req, res, next) {

// render the error page
res.status(err.status || 500);
res.header(err.headers);
res.render('error');
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-frontend",
"version": "1.0.2",
"version": "1.0.3",
"scripts": {
"start": "node ./bin/www"
},
Expand Down
22 changes: 19 additions & 3 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,25 @@ function build_projection(fields){

function mongo_package_info(package, universe){
return mongo_find({_user: universe, Package: package}).toArray().then(function(docs){
if(!docs.length)
throw createError(404, `Package ${package} not found in ${universe}`)
return group_package_data(docs);
if(docs.length){
return group_package_data(docs);
} else {
// Try to find pkg elsewhere...
var altquery = {
_type: 'src',
Package : {$regex: `^${package}$`, $options: 'i'},
'$or' : [{'_universes': universe}, {'_indexed': true}]
}
return mongo_find(altquery).next().then(function(alt){
if(alt){
throw createError(301, `Package has moved...`, {headers : {
location: `https://${alt._user}.r-universe.dev/${alt.Package}`
}});
} else {
throw createError(404, `Package ${package} not found in ${universe}`)
}
});
}
});
}

Expand Down

0 comments on commit 670f855

Please sign in to comment.