Guest User

Untitled

a guest
Oct 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. const json = require('./routes.json')
  2. const _ = require('lodash')
  3. routes.use(function(req, res, next) {
  4.  
  5. let str = req.path
  6. let path = str.split('/')[1]
  7.  
  8. // [Request] => /test/123
  9. console.log(path)
  10. // [Result] => test
  11.  
  12. let test = _.find(json.routes, function(item) {
  13. return item.path.match(new RegExp('^/' + path + '*'))
  14. })
  15. console.log(test)
  16. //{"path" : "/test/:id", "target" : "localhost:2018", "message" : "This is Test Response" },
  17.  
  18. routes.get(test.path, function(req, res) {
  19. res.json("Done")
  20. })
  21. })
Add Comment
Please, Sign In to add comment