How to check if an API's "uris" property contains current request uri?
271 views
Skip to first unread message
jg
unread,
Nov 10, 2017, 10:06:44 AM11/10/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Kong
Hello Kongers,
I'm new to Kong and Lua, but it's been great so far. I'm having an issue when developing a plugin that I was hoping to get some help with. How do you tell if the current request matches a uri in an API's "uris" array?
If the API has uris of "/test","/what" how can I tell if a consumer calls the API gateway route of "example.com/what" from a plugin (from within the plugin's access method)?
Any help would be appreciated.
mvanho...@xebia.com
unread,
Nov 10, 2017, 12:49:56 PM11/10/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Kong
You could retrieve the current uri though ngx.var.uri but I would say it is against the design of kong. If you want different behaviour for /what as for /test than you declare two different plugins..
Cheers,
Mark
Thibault Charbonnier
unread,
Nov 10, 2017, 1:24:55 PM11/10/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to kong...@googlegroups.com
Hi,
If you are using Kong 0.11 or above, you can use the following structure
in the access() handler and all subsequent ones:
ngx.ctx.router_matches
It contains the following properties:
uri (string or nil)
host (string or nil)
method (string or nil)
uri_captures (table or nil)
This is not yet officially documented as it isn't quite yet part of our
official API.