mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-12 23:45:57 +00:00
added the search api with pagnination, and added a remove invalid brew endpoint to the admin
This commit is contained in:
55
server.js
55
server.js
@@ -8,9 +8,6 @@ var app = express();
|
||||
app.use(express.static(__dirname + '/build'));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
|
||||
|
||||
|
||||
//Mongoose
|
||||
var mongoose = require('mongoose');
|
||||
var mongoUri = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/naturalcrit';
|
||||
@@ -19,54 +16,32 @@ mongoose.connection.on('error', function(){
|
||||
console.log(">>>ERROR: Run Mongodb.exe ya goof!");
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//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){
|
||||
|
||||
//Remove the text to reduce the response payload
|
||||
homebrews = _.map(homebrews, (brew)=>{
|
||||
brew.text = brew.text != '';
|
||||
return brew;
|
||||
});
|
||||
|
||||
console.log("HOMEBREW", homebrews.length);
|
||||
*/
|
||||
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)
|
||||
});
|
||||
// });
|
||||
vitreumRender({
|
||||
page: './build/admin/bundle.dot',
|
||||
prerenderWith : './client/admin/admin.jsx',
|
||||
clearRequireCache : !process.env.PRODUCTION,
|
||||
initialProps: {
|
||||
url: req.originalUrl,
|
||||
admin_key : process.env.ADMIN_KEY,
|
||||
},
|
||||
}, function (err, page) {
|
||||
return res.send(page)
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//Populate homebrew routes
|
||||
app = require('./server/homebrew.api.js')(app);
|
||||
app = require('./server/homebrew.server.js')(app);
|
||||
|
||||
@@ -75,14 +50,12 @@ app = require('./server/homebrew.server.js')(app);
|
||||
app.get('*', function (req, res) {
|
||||
vitreumRender({
|
||||
page: './build/naturalCrit/bundle.dot',
|
||||
globals:{
|
||||
|
||||
},
|
||||
globals:{},
|
||||
prerenderWith : './client/naturalCrit/naturalCrit.jsx',
|
||||
initialProps: {
|
||||
url: req.originalUrl
|
||||
},
|
||||
clearRequireCache : true,
|
||||
clearRequireCache : !process.env.PRODUCTION,
|
||||
}, function (err, page) {
|
||||
return res.send(page)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user