1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-12 23:35:58 +00:00

Swapped over all urls and refs to old url scheme

This commit is contained in:
Scott Tolksdorf
2016-06-04 18:29:25 -04:00
parent 60092f404c
commit 7ca4e8ffa6
17 changed files with 144 additions and 401 deletions

113
server.js
View File

@@ -43,17 +43,120 @@ app.get('/admin', function(req, res){
//Populate homebrew routes
app = require('./server/homebrew.api.js')(app);
app = require('./server/homebrew.server.js')(app);
//app = require('./server/homebrew.server.js')(app);
var HomebrewModel = require('./server/homebrew.model.js').model;
//Edit Page
app.get('/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('/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('/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('/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');
app.get('*', function (req, res) {
vitreumRender({
page: './build/main/bundle.dot',
page: './build/homebrew/bundle.dot',
globals:{},
prerenderWith : './client/main/main.jsx',
prerenderWith : './client/homebrew/homebrew.jsx',
initialProps: {
url: req.originalUrl
url: req.originalUrl,
welcomeText : welcomeText,
changelog : changelogText
},
clearRequireCache : !process.env.PRODUCTION,
}, function (err, page) {
@@ -62,6 +165,8 @@ app.get('*', function (req, res) {
});
var port = process.env.PORT || 8000;
app.listen(port);
console.log('Listening on localhost:' + port);