Skip to content

Commit

Permalink
factor out global pages into another router
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Aug 11, 2024
1 parent 62bb38f commit 551b8d5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var globalRouter = require('./routes/global');
var universeRouter = require('./routes/universe');
var pkginfoRouter = require('./routes/pkginfo');

Expand Down Expand Up @@ -44,6 +45,7 @@ app.use(function(req, res, next){
next();
})

app.use('/', globalRouter);
app.use('/', universeRouter);
app.use('/', pkginfoRouter);

Expand Down
9 changes: 9 additions & 0 deletions routes/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const express = require('express');
const router = express.Router();
const db = require("../src/db.js");

router.get("/_global/search", function(req, res, next){
res.render("search");
});

module.exports = router;
3 changes: 3 additions & 0 deletions routes/pkginfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ function description_to_html(txt = ""){
}

router.get('/:package', function(req, res, next) {
if(req.params.package.startsWith("_")){
return next();
}
return db.get_package_info(req.params.package, req.universe).then(function(pkgdata){
pkgdata.format_count = format_count;
pkgdata.universe = pkgdata._user;
Expand Down
4 changes: 0 additions & 4 deletions routes/universe.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ router.get("/articles/:package/:vignette", function(req, res, next){
}).catch(next);
});

router.get("/search", function(req, res, next){
res.render("search");
});

router.get('/favicon.ico', function(req, res, next) {
res.status(404).send("No favicon yet");
});
Expand Down

0 comments on commit 551b8d5

Please sign in to comment.