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

Added in the admin page

This commit is contained in:
Scott Tolksdorf
2016-01-06 20:04:45 -05:00
parent 25b53a7c24
commit 46186c0de2
11 changed files with 224 additions and 16 deletions

View File

@@ -19,9 +19,46 @@ mongoose.connection.on('error', function(){
});
//Admin route
process.env.ADMIN_USER = process.env.ADMIN_USER || 'admin';
process.env.ADMIN_PASS = process.env.ADMIN_PASS || 'password';
process.env.ADMIN_KEY = process.env.ADMIN_KEY || 'admin_key';
var auth = require('basic-auth');
var HomebrewModel = require('./server/homebrew.model.js').model;
app.get('/admin', function(req, res){
var credentials = auth(req)
if (!credentials || credentials.name !== process.env.ADMIN_USER || credentials.pass !== process.env.ADMIN_PASS) {
res.setHeader('WWW-Authenticate', 'Basic realm="example"')
return res.status(401).send('Access denied')
}
HomebrewModel.find({}, function(err, homebrews){
vitreumRender({
page: './build/admin/bundle.dot',
prerenderWith : './client/admin/admin.jsx',
clearRequireCache : true,
initialProps: {
url: req.originalUrl,
admin_key : process.env.ADMIN_KEY,
homebrews : homebrews,
},
}, function (err, page) {
return res.send(page)
});
});
});
app = require('./server/homebrew.api.js')(app);
app.get('*', function (req, res) {
vitreumRender({
page: './build/naturalCrit/bundle.dot',