Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs/cors rutta #399

Merged
merged 4 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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