-
Notifications
You must be signed in to change notification settings - Fork 115
New Feature: Path based parameters #119
Conversation
Appveyor is still drunk, but tests appear to be passing. Take a look at the changes and let me know what you think @tylerl0706 https://ci.appveyor.com/project/PowerShell/polaris/build/job/0qxc0cy0p5bd54g9 |
I'll look at this :) p.s. tweeted at AppVeyor to save us! https://twitter.com/TylerLeonhardt/status/992997043433099264 |
Thinking about this a bit more last night. If you like the concept I may just look into porting the module expressjs uses. It would give a more familiar syntax and theirs is pretty robust. |
@Tiberriver256 THIS IS AWESOME AND EXACTLY WHAT POLARIS NEEDS. Adopting what expressjs does sounds awesome for this - that's one of my favorite features of express actually. |
Do you still want me to review this or do you want to take a crack at following what expressjs does 😀 |
I’ll take a crack at the expressjs :) doesn’t look too bad.
…On Sun, May 6, 2018 at 10:37 PM Tyler James Leonhardt < ***@***.***> wrote:
Do you still want me to review this or do you want to take a crack at
following what expressjs does 😀
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#119 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGqmtAXySXg5JN1DmMJrQeWMDGVNQ5cpks5tv7NSgaJpZM4Tz4dA>
.
|
Nice enhancement, but the implementation makes certain assumptions about our desired end state that may make sense in the context of the this enhancement, but may not be valid for other desired behaviors. I would prefer if we take the time to discuss and agree on a set of behaviors and design requirements, so that we can design an elegant, comprehensive solution, rather than hoping we get there through a series of small breaking bug fixes and enhancements taking us in random directions. |
@TimCurwick - Agreed, I think the goal of my PR here (which was to get the discussion started) is not really standard. I opened #120 to start the discussion. Really glad people are getting into this! |
I updated the code here as a first stab at RFC001 (#120). Everything is working and has a test case for the examples I gave. It does not have a method for switching from case sensitive to being insensitive yet. *EDIT: Looks like I've actually got one test to fix on the linux side but the code should still be okay to look at. |
I'm waiting on how the RFC turns out before reviewing :) just so you know I haven't forgotten about this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tiberriver256 I owe you an apology for disappearing! Some other work has taken priority but I still deeply care about this project.
If fact, I'm going to be giving a talk that uses Polaris in the coming months :) ... more on that later.
I have a few comments on this PR. This is the last thing I want to get in before I push it out to the Gallery. I've got the signing process almost set up... and then in the future, it will be 100% automated and we'll be able to iterate much faster.
Again, I'm sorry for disappearing and hope that you still have an interest in Polaris!
PS. The RFC time period is over and I think we should get this in.
lib/Polaris.Class.ps1
Outdated
@@ -48,7 +48,8 @@ class Polaris { | |||
# Run middleware in the order in which it was added | |||
foreach ($Middleware in $Polaris.RouteMiddleware) { | |||
$InformationVariable += $Polaris.InvokeRoute( | |||
$Middleware.Scriptblock, | |||
$Middleware.Scriptblock, | |||
$Null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: some weird indenting!
lib/Polaris.Class.ps1
Outdated
@@ -68,7 +75,8 @@ class Polaris { | |||
try { | |||
|
|||
$InformationVariable += $Polaris.InvokeRoute( | |||
$Routes[$MatchingRoute][$Request.Method], | |||
$Routes[$MatchingRoute][$Request.Method], | |||
$Parameters, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit some more weird indents
lib/Polaris.Class.ps1
Outdated
@@ -192,6 +201,23 @@ class Polaris { | |||
return $SanitizedPath | |||
} | |||
|
|||
static [RegEx] ConvertPathToRegex([string]$Path){ | |||
Write-Debug "Path: $path" | |||
$path = $path -replace '\.', '\.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this replace doing anything?
lib/Polaris.Class.ps1
Outdated
$path = $path -replace '-', '\-' | ||
$path = $path -replace '\*', '.*' | ||
$path = "^$path$" | ||
$path = $path -replace ":(\w+)(\?{0,1})", '(?<$1>.+)$2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a couple comments in this function due to the complexity?
# Searching for the first route that matches by the most specific route paths first. | ||
# | ||
$MatchingRoute = $Routes.keys | Sort-Object -Property Length -Descending | Where-Object { $Route -match [Polaris]::ConvertPathToRegex($_) } | Select-Object -First 1 | ||
$Request.Parameters = ([PSCustomObject]$Matches) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does $Matches
get defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$Matches is an automatic variable that gets defined every time you run a -match comparison.
See:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-6#matches
https://mcpmag.com/articles/2015/09/30/regex-groups-with-powershell.aspx
Also that test failure is bogus...
Maybe do a different kind of comparison rather than a string compare. |
Yeah, no worries on the timing. My life kind of blew up for a bit there too but seems to be close to returning to normalcy. It might be a bit before I can get to cleaning this up but super excited to do it. |
@Tiberriver256 Got all the release stuff done so as soon as we get this PR in I'll throw Polaris up on the Gallery! |
Gentle ping 😊 I'd like to get this on the Gallery. |
Thanks Tyler. I haven't forgotten. I'll see if I can get this up tonight.
…On Mon, Aug 6, 2018 at 11:07 AM Tyler James Leonhardt < ***@***.***> wrote:
Gentle ping 😊
I'd like to get this on the Gallery.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#119 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGqmtNIfKHATErdrW4MslM4U0P4enUbPks5uOFvKgaJpZM4Tz4dA>
.
|
Should be all set sir :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Whooooooo!! |
*Note this should also fix the matching issue described at the bottom of issue #116
This allows for the following scenario:
It introduces a new $Parameters PSCustomObject representing any path based parameters and it also makes route matching more strict as it is now converts paths to a regular expression using Convert-PathParameters function.
At the time a request is made the above mentioned path
/Hello/{Name}
would get converted to a regular expression of^/Hello/(?<Name>.*)$
for matching against the client's requested route.A more basic example would be that
/Hello
would be converted to^/Hello$
to guarantee an exact path match. I've also added some test cases to ensure we are throwing 404 errors for paths that don't match exactly.