Sails.js dot in route param

Viewed 683

I am trying to get this route to work

items/images/myimg.jpg

It responses 404 but work with

items/images/myimg

Also works with

items/images/myimg.jpg/

I tried the following router configuration

'get /items/images/:imageName': {
  action: 'items/images/find',
  skipAssets: true,
}

EDIT:

If I set skipAssets: false then the response will be unauthorized. I have the following ACL

'*': false,
'items/images/find': 'isLoggedIn',

In the isLoggedIn.js policy the req.session is undefined even when the user has a valid session.

if I set 'items/images/find': true it will work but I want access control for this route.

1 Answers

The route should be set like this:

'get /items/images/:imageName': {
  action: 'items/images/find',
  skipAssets: false,
}

This method should be added to config/session.js:

isSessionDisabled: function (req){
  // Allow session for all item image requests.
  if (req.path.match(/^\/items\/images\//) { 
    return false; 
  }
  // Otherwise, disable session for all requests that look like assets.
  return !!req.path.match(req._sails.LOOKS_LIKE_ASSET_RX);
}

More can be read about this here: https://github.com/balderdashy/sails/issues/4216#issuecomment-337613995

Related