How to actually use Responses with Serverless websocket? - serverless-framework

The documentation https://www.serverless.com/framework/docs/providers/aws/events/websocket#respond-to-a-ws-client-message is not clear at all. The example given is
events:
- websocket:
route: hello
routeResponseSelectionExpression: $default
What does route: hello mean? Is it becoming part of the wss:// URL somehow?
What are the possible values of routeResponseSelectionExpression? Is that the same $default as defined in routes or is that a default expression?

Related

vite-plugin-pages - Route with params/props (Not in URL)

What structure should be used to generate a route that accepts a param(s).
Eg.
i have pages/verify.vue which produces a verify route.
However when i use
router.push({ name: 'verify', params: { phone: '+18383' } })
the route is changed to the verify page but the params are discarded because they were not preset on the route.The warning below is thrown:
[Vue Router warn]: Discarded invalid param(s) "phone" when navigating.
What to do to solve this issue without without switching to manual route definitions?
NOTE: I prefer not to have the param values in the url!
Way forward:
It seems file system routes have no way of allowing props through except through the URL. I will be moving on with Pinia (State Management) as a workaround for this task.
OP will be using Pinia for the given use case, as a workaround.
More alternatives are available here: vite-plugin-pages - Route with params/props (Not in URL)

Getting illegal character when sending GET request in JMETER. Working fine in browser

Im getting illegal character in JMETER for GET request -
https://dev1/api/v1/query/job/?filter={%22job_manager_id%22:%22553f2350-12d3-4252-8fe0-39691019c495%22}
tried replacing %22 with "" but still getting illegal character.
Any solutions ?
I think problematic characters are { and }, they need to be percent-encoded
The options are in:
Tick "URL-encode" box next to the filter parameter in the HTTP Request sampler :
Use __urlencode() function in "Path" field like
see Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept
Or just hard-code the percent-encoded Path part like:
https://dev1/api/v1/query/job/?filter=%7B%22job_manager_id%22%3A%22553f2350-12d3-4252-8fe0-39691019c495%22%7D

Combine IpWhitelist and Errors Middlewares. Is it possible?

I would like to do the following. Combine these two middlewares. If the user is not in the whitelist, then show an error page.
As far as I understand these 2 middlewares don't work together? Or can they be combined somehow? Didn't find anything in the documentation.
IpWhitelist works, but i become only text in Response, but I would like to get an error page.
................
entryPoints:
- websecure
middlewares:
- d-whitelist
- service-errorpages
.................
and
middlewares:
d-whitelist:
ipWhiteList:
sourceRange:
- "95.95.95.95/32"
service-errorpages:
errors:
status:
- "401"
- "403"
- "404"
- "500"
service: tools
query: "/{status}.html"
Thanks!
When defining middleware on a service, it is dependent on order within the array. If you flip service-errorpages and d-whitelist around, you will get a 403 response served from service-errorpages when requesting from a non-whitelisted IP.
If you have a lot of services using the same middleware (eg. both the whitelist & the error handler) with the same priority order, you may benefit from using a chain.

Traefik - apply middleware to router except a specific path

I use a IP whitelist middleware to filter the access of my web application to some IPS only and it works.
But, I want to unprotect a specific path to make it public (the path is /api/transaction).
For now, I have (in my docker-comose.yml) :
varnish:
labels:
- "traefik.http.routers.api_varnish.rule=Host(`api.local`, `api`)"
- "traefik.http.routers.api_varnish.tls=true"
- "traefik.http.routers.api_varnish.middlewares=https-redirect#file"
- "traefik.http.routers.api_varnish.middlewares=https-whitelist#file"
- "traefik.http.services.api_varnish.loadbalancer.server.port=80"
This part works, then I added:
# Open middleware for payment IPN calls
- "traefik.http.routers.api_varnish_transaction.rule=(Host(`api.local`, `api`) && PathPrefix(`/api/transaction`))"
- "traefik.http.routers.api_varnish_transaction.tls=true"
- "traefik.http.routers.api_varnish_transaction.priority=2"
- "traefik.http.routers.api_varnish_transaction.middlewares=https-redirect#file"
I duplicated the lines, but I didn't apply the middleware https-whitelist#file to the new host.
It doesn't work, I can't find the correct syntax or be sure if I can do it ? documentation is pretty poor.
Any idea?
Have 2 routers, 1 for /api/transaction and another one for /* and give the first router a higher priority (set a higher number) e.g.
# ...
labels:
- traefik.http.routers.router_1.priority=2
Now requests to /api/transaction will only hit router_1
https://doc.traefik.io/traefik/routing/routers/#priority

How to validate or filter a wildcard in path for http endpoints in Serverless and AWS API gateway before the process triggs the lambda function?

I have the following http path devices/{sn} in a Serverless-AWS APIgateway API. The wildcard sn is a 15 digits [A-Z0-9] pattern.
In the API today any string that is not recognized as a valid path is redirected to this end-point. Ex: devices/test goes to devices/{sn}, devices/bla goes to devices/{sn} and so on. All those strings will query the database and return null because there is no such sn in the table. I could create a validation process inside the lambda to avoid the unnecessary database query. But I want to save lambda resource and I would like to validate before call the lambda.
This is what I have today for this endpoint:
- http:
path: devices/{sn}
method: GET
private: false
cors: true
authorizer: ${file(env.yml):${self:provider.stage}.authorizer}
request:
parameters:
paths:
sn: true
How can I setup this validation or filter in Serverless.yml?
In fact it should be a very straight-forward functionality of AWS/Serverless.
Let's say we have the following scenario: myPath/{id}. In this case id is a integer (a pk in a table). If I type myPath/blabla it will trigg the lambda. The system will spend resource. It shoul have a kind of previous validation - trig the endpoint only if the {id} === integer.
Your issue is very similar to this issue
According to the post and from my experience, No, I don't think you can perform validation in api-gateway level.