I am building a simple sails.js project and implementing the front end with backbone.
Ideally I want a single route to the one index page in which my backbone app is served.
'/*': {
view: 'home/index'
}
This is great, so any URL now goes to the homepage. Except now, all the routes to any assets (.js, .css, .html, .jpg) do not work anymore.
I can see this comment in the 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 ".":
// (e.g. your javascript, CSS, and image files)
'get /*(^.*)': 'UserController.profile'
But it doesn't make any sense to me. How do I ignore routes with a file extensions.
I have also prefixed all my CRUD url's with 'api', localhost:1337/api/controller/
so a regex route to exclude forwarding those would also be required. I cannot find any information on how to do this anywhere.
I must be missing something fundamental here.
Thanks!
You can use the skipAssets and skipRegex flags. This will not step on your static assets and will not block your api urls starting with /api. I use this with sails.js and angular in html5Mode.
"get *":{
controller:"PagesController",
action:"index",
skipAssets: true,
skipRegex: /^\/api\/.*$/
}
I think this is a bug but I found a workaround solution.
'get /[^.?]+?': 'UserController.profile'
or you can use other one. only /user
and /profile
will exec UserController.profile
. static directory still work great.
'get /:action( user | profile)': 'UserController.profile'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With