Skip to content

Commit

Permalink
Merge pull request #399 from logary/bugs/cors-rutta
Browse files Browse the repository at this point in the history
Bugs/cors rutta
  • Loading branch information
haf authored Mar 4, 2019
2 parents c6f587a + e22829e commit fe5b36c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y locales && \
locale-gen C C.UTF-8 && \
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales && \
DEBIAN_FRONTEND=noninteractive apt-get install -y git vim libczmq4 libprotobuf-c-dev libprotobuf-dev libprotobuf10 ca-certificates
DEBIAN_FRONTEND=noninteractive apt-get install -y git vim libzmq3-dev libczmq4 libprotobuf-c-dev libprotobuf-dev libprotobuf10 ca-certificates && \
ldconfig

ENV LC_ALL=C.UTF-8

Expand Down Expand Up @@ -38,7 +39,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y locales && \
locale-gen C C.UTF-8 && \
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales && \
DEBIAN_FRONTEND=noninteractive apt-get install -y libczmq4 libprotobuf-c-dev libprotobuf10 ca-certificates
DEBIAN_FRONTEND=noninteractive apt-get install -y libczmq4 libprotobuf-c-dev libprotobuf10 ca-certificates && \
ldconfig

WORKDIR /logary/
COPY --from=build /build/src/services/Logary.Services.Rutta/bin/Release/netcoreapp2.2/linux-x64/publish/* /logary/
Expand Down
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 5.0.0-rc.3
* Correct ZMQ installation in Debian-based Dockerfile for Rutta, thanks @haf
* Correct response headers for CORS POST requests for /i/logary, thanks @haf

#### 5.0.0-rc.2
* Enable project id discoverability with google metadata server in Stackdriver, thanks @haf
* Create a new Google BigQuery target, thanks @haf
Expand Down
29 changes: 19 additions & 10 deletions src/ingestion/Logary.Ingestion.HTTP/HTTP.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ module HTTP =
open System
open Impl
open Logary.Adapters.Facade


let withOrigin config next =
warbler (fun ctx ->
let o = ctx.request.header "origin" |> Choice.orDefault (fun () -> "http://localhost")
let ao = config.accessControlAllowOrigin o
next ao)

let CORS (config: HTTPConfig) =
if config.allowCORS then
warbler (fun ctx ->
let o = ctx.request.header "origin" |> Choice.orDefault (fun () -> "http://localhost")
let ao =
config.accessControlAllowOrigin o
let h =
ctx.request.header "access-control-request-headers"
|> Choice.map (fun h -> h.Split([|','|], StringSplitOptions.RemoveEmptyEntries) |> List.ofArray)
Expand All @@ -154,22 +157,28 @@ module HTTP =
|> String.concat ", "
let aa = string config.accessControlMaxAge.TotalSeconds

ao.asWebPart
withOrigin config (fun ao -> ao.asWebPart)
>=> setHeader "Access-Control-Allow-Methods" am
>=> setHeader "Access-Control-Allow-Headers" ah
>=> setHeader "Access-Control-Max-Age" aa)
>=> setHeader "Content-Type" "text/plain; charset=utf-8"
>=> OK ""
else
never

let api (config: HTTPConfig) next: WebPart =
setMimeType "application/json; charset=utf-8" >=> choose [
GET >=> path config.rootPath >=> printHelp config
OPTIONS >=> CORS config
POST >=> path config.rootPath >=> Impl.ingestWith (config.onSuccess, config.onError) next

OPTIONS
>=> CORS config

POST
>=> path config.rootPath
>=> withOrigin config (fun ao -> ao.asWebPart)
>=> Impl.ingestWith (config.onSuccess, config.onError) next
]

let recv (started: IVar<unit>, shutdown: IVar<unit>) config next =
job {
//LogaryFacadeAdapter.initialise<Suave.Logging.Logger> config.logary
Expand All @@ -189,4 +198,4 @@ module HTTP =
}

let create: ServerFactory<HTTPConfig> =
IngestServer.create recv
IngestServer.create recv

0 comments on commit fe5b36c

Please sign in to comment.