Starting to add ability to make admin API requests

master
Mark Moffat 2019-06-15 10:26:03 +09:30
parent 948ff11030
commit ca7043be2a
3 changed files with 29 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
node_modules/
data/
/config/settings-local.json
/config/*-local.json
.vscode
**.DS_Store

2
app.js
View File

@ -252,11 +252,11 @@ app.use((req, res, next) => {
// update config when modified
app.use((req, res, next) => {
next();
if(res.configDirty){
config = common.getConfig();
app.config = config;
}
next();
});
// Ran on all routes

View File

@ -11,7 +11,15 @@ router.get('/admin/orders', common.restrict, (req, res, next) => {
if(err){
console.info(err.stack);
}
res.render('orders', {
// If API request, return json
if(req.apiAuthenticated){
return res.status(200).json({
orders
});
}
return res.render('orders', {
title: 'Cart',
orders: orders,
admin: true,
@ -39,7 +47,15 @@ router.get('/admin/orders/bystatus/:orderstatus', common.restrict, (req, res, ne
if(err){
console.info(err.stack);
}
res.render('orders', {
// If API request, return json
if(req.apiAuthenticated){
return res.status(200).json({
orders
});
}
return res.render('orders', {
title: 'Cart',
orders: orders,
admin: true,
@ -91,7 +107,15 @@ router.get('/admin/orders/filter/:search', common.restrict, (req, res, next) =>
if(err){
console.info(err.stack);
}
res.render('orders', {
// If API request, return json
if(req.apiAuthenticated){
return res.status(200).json({
orders
});
}
return res.render('orders', {
title: 'Order results',
orders: orders,
admin: true,