From ef83dba4a83e23e38b67ee31b79e79c9e25a003d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 21 Apr 2017 16:03:11 -0400 Subject: display orders per product, download as csv --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'index.js') diff --git a/index.js b/index.js index 5f5f45c..f174bbe 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,8 @@ var basic = auth.basic({ } ) +var db = require('./db') + var server, app var site = {} @@ -25,7 +27,8 @@ site.init = function(){ app.use(express.static('views')) app.use(auth.connect(basic)) - // app.get('/admin', auth.connect(basic), site.admin) + app.get('/api/products', site.json(db.products)) + app.get('/api/orders', site.json(db.ordersBySku)) var server = http.createServer(app).listen(process.env.PORT, function () { var port = server.address().port @@ -33,6 +36,14 @@ site.init = function(){ }) } +site.json = function(method){ + return function(req, res){ + method(req.query.id).then(function(data){ + res.json(data) + }) + } +} + site.init() -- cgit v1.2.3-70-g09d2