Sails give 404 on get-parameters with "." - node.js

I have SPA sails app. All route i my SPA app, at first enter in welcome action controller.
'/*' :{
controller : 'Web/welcomeController',
skipAssets : true
}
All others routes using like api, for ajax request. This route '/*' using just for first render page. All others render provide angularjs. And there, one of route have get parameter with dot.
http://localhost:1337/search?lat=40.714545&long=-74.007112
And I get 404 error. All this is due to the parameter skipAsset, which ignores url with the content dot.
I need to controller also skip assets resource like image, js, ect. But correctly process requests with get parameters which content dot /?lat=40.714545&long=-74.007112

skipAssets should probably be fixed to ignore the query string. But in the meantime, you can use skipRegexinstead of skipAssets. From the Sails.js docs on custom routes:
If skipping every URL containing a dot is too permissive, or you need
a route's handler to be skipped based on different criteria entirely,
you can use skipRegex. This option allows you to specify a regular
expression or array of regular expressions to match the request URL
against; if any of the matches are successful, the handler is skipped.
Note that unlike the syntax for binding a handler with a regular
expression, skipRegex expects actual RegExp objects, not strings.
So something like:
'/*' :{
controller : 'Web/welcomeController',
skipRegex : /^[^?]+\./
}
would probably be sufficient.

Related

How to setup Solr search across REST urls

We are implementing an API Portal and have a field named basePath to hold the base part of the api's rest url. Currently the field is defined as a string mapped to solr.StrField but we have search problems with this.
The problem right now is that in order to find an API by the basePath, we need double quote the value in the search. For example name:"/v1/api-proxy/generator" We cannot use name:/v1/api-proxy/* to see other apis that might have clashing urls. We know we have other urls like '/v1/api-proxy/validator' but something like name:/v1/api-proxy/* doesn't return any hits.
I am guessing a first step is to change away from 'string' to text or text_general, but how can search and find other hits that closely match the provided basePath?

Jmeter For each Controller

I've created in Jmeter the follwing:
HTTP Request (first one)
(Regular Expression Extractor) for the Response Body (I set the name of the variable, and put the correct regular expression,which works fine and returns the searched pattern)
(ForEach Controller) to iterate the Array (and of course I put the name of the array variable, and the ouput variable name (index))
another subsequent Http Request under (ForEach Controller Level) (then I put the value index of the array on the path like: /${smalpl_index}
Now I expect the second http Request below the (ForEach Controller) make a new Request based on the index Element of the Array from the Regular Expression, however I got null on the request...(see below)
Hier you find all the screenshot of the test scenario:
https://imgur.com/a/Eqbk9Mx#cp5raNc
GET http://edge.flowplayer.org/null
I see only one request in your screenshot and my expectation is that you should have at least one passed HTTP Request (first one)
In the Regular Expression Extractor make sure to set "Match No." to -1
Add Debug Sampler after the HTTP Request (first one) and make sure it contains the variables you're looking for, in order for ForEach Controller to work you need to have the following variables pattern:
var_1=some value
var_2=some other value
etc.
Check out Using Regular Expressions in JMeter article for example of extracting all links from the page and opening them via ForEach Controller.
Also for the majority of HTML responses using Regular Expressions is not the best idea, it might be better to consider CSS Selector Extractor
The problem was in the regular expression template,since I'm searching for the entire pattern , I should not put $1$, instead of $0$,because $1$ means the second group number, and in my case I have one group, and so it works fro me...

Difference between operators in a URL

What's the difference between using : and ? in a URL? For example /products/:id and /products?id=1? I am trying to get the values from the URL like this Product.findById (req.params.id) but I was wondering which one is most suitable. I know using : do I have to use req.params and ? req.query but I don't understand the difference between them, are they the same?
in my point of view, it is totally different if you are using RESTFUL API pattern
/products/:id called path parameters
The path parameters determine the resource you’re requesting for. Think of it like an automatic answering machine that asks you to press 1 for service, press 2 for another service, 3 for yet another service and so on.
Path parameters are part of the endpoint itself and are not optional
but query parameters
Technically, query parameters are not part of the REST architecture, and they used to help you completely understand how to read and use API’s Query parameters give you the option to modify your request with key-value pairs.
Having your parameters in the query is conceptually optional to the router, query parameters are more of properties and descriptions of the request itself, like when saying GET /users?sort=asc, in this case, the sort attribute was more of a description to the request and the request could complete the fetch without it, that might not always be the case, but a query parameter still describes its request even if it was mandatory.
On the other hand, URL parameters are part of the request itself, the URL without the parameter doesn't make sense, like GET /users/:userID, in this case, not supplying userID will supply unexpected data (A list of users for example) if it didn't break the router completely. URL parameters play part in defining the request rather than just describing it, and they can't be optional.

Are this two routes same in nodejs?

Routes in Express:
/search/:company-name
/search/:category-name
I can see that first one is fired for both requests so they are same, but is there a way to solve this without involving for example:
/search/company/:company-name
/search/category/:category-name
Yes, they are the same.
The router just see a route that starts with search/ and ends with a wildcard. The only thing that change is the name you give to that wildcard, which doesn't matter for the router, it's still the same URL.
You can solve this by either changing the route, or you can parse the route argument (the wildcard) and do something different depending on its value.
You could use a query instead of a param.
Your urls would be:
/search?company=company-name
/search?category=category-name
Your route is /search and you use req.query instead of req.params.
It's either that,
or your solution of changing the route,
or somehow parsing the parameter to decide whether it's a company or a category
or changing your route to a post and using key-value pairs in the post body

Correct order of connect.js middlewares?

middleware depend on each other, for example methodOverride() checks
req.body.method for the HTTP method override, however bodyParser()
parses the request body and populates req.body. Another example of
this is cookie parsing and session support, we must first use()
cookieParser() followed by session()_.
I wonder how can we know which middleware should be use before another? I wonder if there already exist an ordered list (a list with all middlewares in correct working order) somewhere?
The list of middleware on connect's home page is in the correct order, though it doesn't explicitly call out dependencies.

Resources