0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-31 19:32:47 +00:00

Adding a source route instead of jsut opening a new window

This commit is contained in:
Scott Tolksdorf
2016-05-14 13:08:27 -04:00
parent b464de69e3
commit c1d7443c87
5 changed files with 18 additions and 21 deletions

View File

@@ -97,6 +97,18 @@ module.exports = function(app){
});
});
//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('<', '&lt;').replaceAll('>', '&gt;');
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');