Skip to content

Commit

Permalink
Added Domain Filters to the routing
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKirmaier committed Nov 20, 2023
1 parent 9ab278e commit 973ba37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import java.net.URI

case class Request (
url: String,
protocol: String,
domain: String,
port: Int,
origPath: String,
path: String,
directory: String,
Expand Down Expand Up @@ -59,7 +61,7 @@ object Request {
a -> b
}).toMap
val path = uri.getPath
val res = Request(x, uri.getHost,path,path,"/", query,wref_null,wref_null)
val res = Request(x, uri.getScheme, uri.getHost, uri.getPort, path,path,"/", query,wref_null,wref_null)
res
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ trait Route {
}
}
}
def domain(domain: String, route: Route): Route = and((r: Request) => {
println("request domain: " + r.domain)
if(r.domain == domain) {
route.apply(r)
} else {
null
}
})
def path(path: String, route: Route): Route = and((r: Request) => {
if(r.path.startsWith(path + "/")) {
val r2 = r.copy(path = r.path.drop(path.length), directory = r.resolve(path))
Expand Down

0 comments on commit 973ba37

Please sign in to comment.