http_translator: control over port binding
This commit is contained in:
parent
ffbe02898a
commit
7c9765fd23
|
@ -6,6 +6,8 @@ Methods = #{Method} .
|
||||||
; A URL path split into elements
|
; A URL path split into elements
|
||||||
Path = [string ...] .
|
Path = [string ...] .
|
||||||
|
|
||||||
|
Listener = <listen @port int> .
|
||||||
|
|
||||||
; Register an entity that will handle requests at path prefix.
|
; Register an entity that will handle requests at path prefix.
|
||||||
; TODO: assert the public base URL of the handler to the entity.
|
; TODO: assert the public base URL of the handler to the entity.
|
||||||
Handler = <handler @methods Methods @path Path @entity #!any> .
|
Handler = <handler @methods Methods @path Path @entity #!any> .
|
||||||
|
|
|
@ -13,9 +13,8 @@ $other [
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
? <service-object <daemon http_translator> ?cap> [
|
? <service-object <daemon http_translator> ?cap> $cap [
|
||||||
$cap [
|
<listen 8888>
|
||||||
; publish GET requests with prefix "/foo/bar" to other dataspace
|
; publish GET requests with prefix "/foo/bar" to other dataspace
|
||||||
<handler #{GET} ["foo" "bar" ] $other>
|
handler #{GET} ["foo" "bar" ] $other>
|
||||||
]
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -83,7 +83,10 @@ bootDataspace("main") do (ds: Ref; turn: var Turn):
|
||||||
run(parentFacet) do (turn: var Turn): retract(turn, rHandle)
|
run(parentFacet) do (turn: var Turn): retract(turn, rHandle)
|
||||||
hitch(fut, parentFut)
|
hitch(fut, parentFut)
|
||||||
|
|
||||||
|
during(turn, ds, ?Listener) do (port: Port):
|
||||||
var http = newAsyncHttpServer()
|
var http = newAsyncHttpServer()
|
||||||
asyncCheck serve(http, Port 8888, handleRequest)
|
asyncCheck serve(http, port, handleRequest)
|
||||||
|
do:
|
||||||
|
close(http)
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
|
@ -11,6 +11,9 @@ type
|
||||||
`headers`*: Headers
|
`headers`*: Headers
|
||||||
`body`*: string
|
`body`*: string
|
||||||
|
|
||||||
|
Listener* {.preservesRecord: "listen".} = object
|
||||||
|
`port`*: int
|
||||||
|
|
||||||
Handler*[E] {.preservesRecord: "handler".} = ref object
|
Handler*[E] {.preservesRecord: "handler".} = ref object
|
||||||
`methods`*: Methods
|
`methods`*: Methods
|
||||||
`path`*: Path
|
`path`*: Path
|
||||||
|
@ -33,8 +36,9 @@ proc `$`*[E](x: Handler[E]): string =
|
||||||
proc encode*[E](x: Handler[E]): seq[byte] =
|
proc encode*[E](x: Handler[E]): seq[byte] =
|
||||||
encode(toPreserve(x, E))
|
encode(toPreserve(x, E))
|
||||||
|
|
||||||
proc `$`*(x: Path | Headers | Response | Request | Methods): string =
|
proc `$`*(x: Path | Headers | Response | Listener | Request | Methods): string =
|
||||||
`$`(toPreserve(x))
|
`$`(toPreserve(x))
|
||||||
|
|
||||||
proc encode*(x: Path | Headers | Response | Request | Methods): seq[byte] =
|
proc encode*(x: Path | Headers | Response | Listener | Request | Methods): seq[
|
||||||
|
byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserve(x))
|
||||||
|
|
Loading…
Reference in New Issue