mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-27 00:42:40 +00:00
Swapped over all urls and refs to old url scheme
This commit is contained in:
@@ -30,13 +30,13 @@ var getTopBrews = function(cb){
|
||||
|
||||
module.exports = function(app){
|
||||
|
||||
app.get('/homebrew/top', function(req, res){
|
||||
app.get('/api/top', function(req, res){
|
||||
getTopBrews(function(topBrews){
|
||||
return res.json(topBrews);
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/homebrew/api', function(req, res){
|
||||
app.post('/api', function(req, res){
|
||||
var newHomebrew = new HomebrewModel(req.body);
|
||||
newHomebrew.save(function(err, obj){
|
||||
if(err) return;
|
||||
@@ -44,7 +44,7 @@ module.exports = function(app){
|
||||
})
|
||||
});
|
||||
|
||||
app.put('/homebrew/api/update/:id', function(req, res){
|
||||
app.put('/api/update/:id', function(req, res){
|
||||
HomebrewModel.find({editId : req.params.id}, function(err, objs){
|
||||
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
|
||||
var resEntry = objs[0];
|
||||
@@ -58,7 +58,7 @@ module.exports = function(app){
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/homebrew/api/remove/:id', function(req, res){
|
||||
app.get('/api/remove/:id', function(req, res){
|
||||
HomebrewModel.find({editId : req.params.id}, function(err, objs){
|
||||
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
|
||||
var resEntry = objs[0];
|
||||
@@ -70,7 +70,7 @@ module.exports = function(app){
|
||||
});
|
||||
|
||||
//Removes all empty brews that are older than 3 days and that are shorter than a tweet
|
||||
app.get('/homebrew/api/invalid', mw.adminOnly, function(req, res){
|
||||
app.get('/api/invalid', mw.adminOnly, function(req, res){
|
||||
var invalidBrewQuery = HomebrewModel.find({
|
||||
'$where' : "this.text.length < 140",
|
||||
createdAt: {
|
||||
@@ -94,7 +94,7 @@ module.exports = function(app){
|
||||
});
|
||||
|
||||
|
||||
app.get('/homebrew/api/search', mw.adminOnly, function(req, res){
|
||||
app.get('/api/search', mw.adminOnly, function(req, res){
|
||||
var page = req.query.page || 0;
|
||||
var count = req.query.count || 20;
|
||||
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
var _ = require('lodash');
|
||||
var vitreumRender = require('vitreum/render');
|
||||
var HomebrewModel = require('./homebrew.model.js').model;
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = function(app){
|
||||
|
||||
/*
|
||||
app.get('/homebrew/new', function(req, res){
|
||||
var newHomebrew = new HomebrewModel();
|
||||
newHomebrew.save(function(err, obj){
|
||||
return res.redirect('/homebrew/edit/' + obj.editId);
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
|
||||
//Edit Page
|
||||
app.get('/homebrew/edit/:id', function(req, res){
|
||||
HomebrewModel.find({editId : req.params.id}, function(err, objs){
|
||||
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||
|
||||
var resObj = null;
|
||||
var errObj = {text: "# oops\nCould not find the homebrew."}
|
||||
if(objs.length){
|
||||
resObj = objs[0];
|
||||
}
|
||||
|
||||
vitreumRender({
|
||||
page: './build/homebrew/bundle.dot',
|
||||
globals:{},
|
||||
prerenderWith : './client/homebrew/homebrew.jsx',
|
||||
initialProps: {
|
||||
url: req.originalUrl,
|
||||
brew : resObj || errObj
|
||||
},
|
||||
clearRequireCache : !process.env.PRODUCTION,
|
||||
}, function (err, page) {
|
||||
return res.send(page)
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
//Share Page
|
||||
app.get('/homebrew/share/:id', function(req, res){
|
||||
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
||||
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||
|
||||
var resObj = null;
|
||||
var errObj = {text: "# oops\nCould not find the homebrew."}
|
||||
|
||||
if(objs.length){
|
||||
resObj = objs[0];
|
||||
resObj.lastViewed = new Date();
|
||||
resObj.views = resObj.views + 1;
|
||||
resObj.save();
|
||||
}
|
||||
|
||||
vitreumRender({
|
||||
page: './build/homebrew/bundle.dot',
|
||||
globals:{},
|
||||
prerenderWith : './client/homebrew/homebrew.jsx',
|
||||
initialProps: {
|
||||
url: req.originalUrl,
|
||||
brew : resObj || errObj
|
||||
},
|
||||
clearRequireCache : !process.env.PRODUCTION,
|
||||
}, function (err, page) {
|
||||
return res.send(page)
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
//Print Page
|
||||
var Markdown = require('marked');
|
||||
var PHBStyle = '<style>' + require('fs').readFileSync('./phb.standalone.css', 'utf8') + '</style>'
|
||||
app.get('/homebrew/print/:id', function(req, res){
|
||||
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
||||
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||
|
||||
var brew = null;
|
||||
if(objs.length){
|
||||
brew = objs[0];
|
||||
}
|
||||
|
||||
var content = _.map(brew.text.split('\\page'), function(pageText){
|
||||
return '<div class="phb print">' + Markdown(pageText) + '</div>';
|
||||
}).join('\n');
|
||||
|
||||
var dialog = '';
|
||||
if(req.query && req.query.dialog) dialog = 'onload="window.print()"';
|
||||
|
||||
var title = '<title>' + brew.title + '</title>';
|
||||
var page = `<html><head>${title} ${PHBStyle}</head><body ${dialog}>${content}</body></html>`
|
||||
|
||||
return res.send(page)
|
||||
});
|
||||
});
|
||||
|
||||
//Source page
|
||||
String.prototype.replaceAll = function(s,r){return this.split(s).join(r)}
|
||||
app.get('/homebrew/source/:id', function(req, res){
|
||||
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
||||
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||
var brew = null;
|
||||
if(objs.length) brew = objs[0];
|
||||
var text = brew.text.replaceAll('<', '<').replaceAll('>', '>');
|
||||
return res.send(`<code><pre>${text}</pre></code>`);
|
||||
});
|
||||
});
|
||||
|
||||
//Home and 404, etc.
|
||||
var welcomeText = require('fs').readFileSync('./client/homebrew/pages/homePage/welcome_msg.txt', 'utf8');
|
||||
var changelogText = require('fs').readFileSync('./changelog.md', 'utf8');
|
||||
app.get('/homebrew*', function (req, res) {
|
||||
vitreumRender({
|
||||
page: './build/homebrew/bundle.dot',
|
||||
globals:{},
|
||||
prerenderWith : './client/homebrew/homebrew.jsx',
|
||||
initialProps: {
|
||||
url: req.originalUrl,
|
||||
welcomeText : welcomeText,
|
||||
changelog : changelogText
|
||||
},
|
||||
clearRequireCache : !process.env.PRODUCTION,
|
||||
}, function (err, page) {
|
||||
return res.send(page)
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
Reference in New Issue
Block a user