1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-13 16:15:56 +00:00
This commit is contained in:
Scott Tolksdorf
2018-04-08 22:23:03 -04:00
committed by Trevor Buckner
parent 40f1d4c790
commit c8875cff94
51 changed files with 2837 additions and 2852 deletions

View File

@@ -1,10 +1,10 @@
const _ = require('lodash');
const jwt = require('jwt-simple');
const express = require("express");
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/build'));''
app.use(require('body-parser').json({limit: '25mb'}));
app.use(express.static(`${__dirname}/build`));'';
app.use(require('body-parser').json({ limit: '25mb' }));
app.use(require('cookie-parser')());
const config = require('nconf')
@@ -16,18 +16,18 @@ const config = require('nconf')
//DB
require('mongoose')
.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit')
.connection.on('error', () => {
.connection.on('error', ()=>{
console.log('Error : Could not connect to a Mongo Database.');
console.log(' If you are running locally, make sure mongodb.exe is running.');
});
//Account MIddleware
app.use((req, res, next) => {
app.use((req, res, next)=>{
if(req.cookies && req.cookies.nc_session){
try{
try {
req.account = jwt.decode(req.cookies.nc_session, config.get('secret'));
}catch(e){}
} catch (e){}
}
return next();
});
@@ -43,9 +43,9 @@ const changelogText = require('fs').readFileSync('./changelog.md', 'utf8');
//Source page
String.prototype.replaceAll = function(s,r){return this.split(s).join(r)}
String.prototype.replaceAll = function(s, r){return this.split(s).join(r);};
app.get('/source/:id', (req, res)=>{
HomebrewModel.get({shareId : req.params.id})
HomebrewModel.get({ shareId: req.params.id })
.then((brew)=>{
const text = brew.text.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
return res.send(`<code><pre>${text}</pre></code>`);
@@ -53,25 +53,25 @@ app.get('/source/:id', (req, res)=>{
.catch((err)=>{
console.log(err);
return res.status(404).send('Could not find Homebrew with that id');
})
});
});
app.get('/user/:username', (req, res, next) => {
app.get('/user/:username', (req, res, next)=>{
const fullAccess = req.account && (req.account.username == req.params.username);
HomebrewModel.getByUser(req.params.username, fullAccess)
.then((brews) => {
.then((brews)=>{
req.brews = brews;
return next();
})
.catch((err) => {
.catch((err)=>{
console.log(err);
})
})
});
});
app.get('/edit/:id', (req, res, next)=>{
HomebrewModel.get({editId : req.params.id})
HomebrewModel.get({ editId: req.params.id })
.then((brew)=>{
req.brew = brew.sanatize();
return next();
@@ -84,7 +84,7 @@ app.get('/edit/:id', (req, res, next)=>{
//Share Page
app.get('/share/:id', (req, res, next)=>{
HomebrewModel.get({shareId : req.params.id})
HomebrewModel.get({ shareId: req.params.id })
.then((brew)=>{
return brew.increaseView();
})
@@ -100,7 +100,7 @@ app.get('/share/:id', (req, res, next)=>{
//Print Page
app.get('/print/:id', (req, res, next)=>{
HomebrewModel.get({shareId : req.params.id})
HomebrewModel.get({ shareId: req.params.id })
.then((brew)=>{
req.brew = brew.sanatize(true);
return next();
@@ -115,20 +115,20 @@ app.get('/print/:id', (req, res, next)=>{
//Render Page
const render = require('vitreum/steps/render');
const templateFn = require('./client/template.js');
app.use((req, res) => {
app.use((req, res)=>{
render('homebrew', templateFn, {
version : require('./package.json').version,
url: req.originalUrl,
welcomeText : welcomeText,
changelog : changelogText,
brew : req.brew,
brews : req.brews,
account : req.account
version : require('./package.json').version,
url : req.originalUrl,
welcomeText : welcomeText,
changelog : changelogText,
brew : req.brew,
brews : req.brews,
account : req.account
})
.then((page)=>{
return res.send(page);
})
.then((page) => {
return res.send(page)
})
.catch((err) => {
.catch((err)=>{
console.log(err);
return res.sendStatus(500);
});