Commit 432957dfe117cf67f338c273bdadfea5664ea0e4
1 parent
65e89a96cb
Exists in
master
APISERVER: /remote-products/set terima qs
Showing 1 changed file with 13 additions and 3 deletions Side-by-side Diff
api-server/router-remote-products.js
... | ... | @@ -20,18 +20,27 @@ function pageIndex(req, res, next) { |
20 | 20 | } |
21 | 21 | |
22 | 22 | function pageSet(req, res, next) { |
23 | - if (!req.params.localProduct || !req.params.localProduct.trim() || !req.params.remoteProduct || !req.params.remoteProduct.trim()) { | |
23 | + function responseWithUsageHelp() { | |
24 | 24 | res.json({ |
25 | 25 | method: '/remote-products/set', |
26 | 26 | error: true, |
27 | 27 | error_msg: 'Usage: /remote-products/set/<LOCAL_PRODUCT>/<REMOTE_PRODUCT>' |
28 | 28 | }); |
29 | + } | |
29 | 30 | |
31 | + if (!req.params.localProduct || !req.query.local) { | |
32 | + responseWithUsageHelp() | |
30 | 33 | return; |
31 | 34 | } |
32 | 35 | |
33 | - const localProduct = req.params.localProduct.trim().toUpperCase(); | |
34 | - const remoteProduct = req.params.remoteProduct.trim(); | |
36 | + if (!req.params.remoteProduct || !req.query.remote) { | |
37 | + responseWithUsageHelp(); | |
38 | + return; | |
39 | + } | |
40 | + | |
41 | + | |
42 | + const localProduct = (req.params.localProduct || req.query.local).trim().toUpperCase(); | |
43 | + const remoteProduct = (req.params.remoteProduct || req.query.remote).trim(); | |
35 | 44 | |
36 | 45 | config.remote_products[localProduct] = remoteProduct; |
37 | 46 | config.remote_products = sortObj(config.remote_products, { |
... | ... | @@ -73,4 +82,5 @@ function pageDel(req, res, next) { |
73 | 82 | |
74 | 83 | router.get('/', pageIndex); |
75 | 84 | router.get('/set/:localProduct/:remoteProduct', pageSet); |
85 | +router.get('/set', pageSet); | |
76 | 86 | router.get('/del/:localProduct', pageDel); |