Sails.js Regular Routes

I create a simple sails.js project and implement the front end with the foundation.

Ideally, I want one route per index page, on which my base application is submitted.

'/*': { view: 'home/index' } 

This is great, so any URL is now sent to the home page. In addition, all routes to any assets (.js, .css, .html, .jpg) no longer work.

I see this comment in config.routes.js :

 // NOTE: // You'll still want to allow requests through to the static assets, // so we need to set up this route to ignore URLs that have a trailing ".": // (eg your javascript, CSS, and image files) 'get /*(^.*)': 'UserController.profile' 

But that makes no sense to me. How to ignore routes with file extensions.

I also prefix all my CRUD urls with api ', localhost:1337/api/controller/ , so a regular route will also be required to prevent forwarding. I cannot find any information on how to do this anywhere.

I have to miss something fundamental here.

Thanks!

+6
source share
2 answers

You can use the skipAssets and skipRegex flags. This will not affect your static assets and will not block your URLs starting with / api. I use this with sails.js and angular in html5Mode.

  "get *":{ controller:"PagesController", action:"index", skipAssets: true, skipRegex: /^\/api\/.*$/ } 
+8
source

I think this is a mistake, but I found a workaround.

'get /[^.?]+?': 'UserController.profile'

or you can use another. only /user and /profile will execute UserController.profile . the static directory is still working fine.

'get /:action( user | profile)': 'UserController.profile'

+2
source

Source: https://habr.com/ru/post/957613/


All Articles