Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const json = require('./routes.json')
- const _ = require('lodash')
- routes.use(function(req, res, next) {
- let str = req.path
- let path = str.split('/')[1]
- // [Request] => /test/123
- console.log(path)
- // [Result] => test
- let test = _.find(json.routes, function(item) {
- return item.path.match(new RegExp('^/' + path + '*'))
- })
- console.log(test)
- //{"path" : "/test/:id", "target" : "localhost:2018", "message" : "This is Test Response" },
- routes.get(test.path, function(req, res) {
- res.json("Done")
- })
- })
Add Comment
Please, Sign In to add comment