javascript - Route param only fetching first letter -


i have following code. lets me fetch image, , specify optionally if recache needed. example, /something.jpg/force. id of image, example /7gdf4g. can see, force param optional.

app.get('/:image/:force?*', function (req, res) {     console.log("image req");     // create variable hold force bool, default false     var force = false;     // check if force bool present     if (req.params.force === ('force' || 'true' || 'recache' || 're-cache')) {         force = true;     }     // pass req, res, image variable , force bool process     mod.request.process({         req : req,         res : res     }, {         type : 'image',         id : req.params.image     }, force); }); 

when run, passed onto mod.request.process() expected. however, if add following see value being returned :image:

console.log(json.stringify(data)); 

this logged:

{"type":"image","id":"k"} 

the input url kmoi9vn.jpg/force, id should kmoi9vn.jpg. if run again something.jpg, {"type":"image","id":"s"}.

any ideas on why might happening?

why not remove asterisk , use /:image/:force??

this works both examples:

var pathtoregexp = require('path-to-regexp');  var keys = []; var exp = pathtoregexp('/:image/:force?', keys); console.dir(exp.exec('/7gdf4g')); console.dir(exp.exec('/something.jpg/force'));  // outputs: // [ '/something.jpg/force', //   'something.jpg', //   'force', //   index: 0, //   input: '/something.jpg/force' ] // [ '/7gdf4g', '7gdf4g', undefined, index: 0, input: '/7gdf4g' ] 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -