1
votes

I have some Routes that are admin specific and some that are not.

I have the below in my code:

val route = pathPrefixTest("admin") { statusRoute ~ statsRoute } ~ securedRoutes

The securedRoutes are public facing and do additional logic like checking a user is logged in, and rejects them if they are not, whereas the admin urls are internal LDAP protected, and hence do not need these checks.

The problem I have, is when someone types "/admin/mispelt_url", it does not meet the admin routes, and tries the secure ones. At this point, it tries to check if the user is logged in, and returns an error that they need to sign in.

What I'd like is:

val route = pathPrefixTest("admin") { statusRoute ~ statsRoute } ~  **pathPrefixTest("NOT admin")** {securedRoutes}

Is there a path matching mechanism for this?

1
Have you tried "admin".! ? - jrudolph

1 Answers

2
votes

From docs, you can use unary_! to say "not admin"

By prefixing a matcher with ! it can be turned into a PathMatcher0 that only
matches if the underlying matcher does not match and vice versa.

Examples -

// matches anything starting with "/foo" except for /foobar
pathPrefix("foo" ~ !"bar")

Hence, you should be able to do(Not tested though)

val route = pathPrefixTest("admin") { statusRoute ~ statsRoute } ~  pathPrefixTest(!"admin") {securedRoutes}