Skip to content

Commit

Permalink
[#501] Trails: Remove CORS middleware.
Browse files Browse the repository at this point in the history
Now that we are going via the EDAPI it adds the CORS headers and it was creating problems that both services were adding CORS headers. We now hand over responsibility for adding the CORS headers to the EDAPI and assume all requests to the Trails service will be proxied by that and have the CORS headers added there.
  • Loading branch information
a-stacey committed Sep 9, 2019
1 parent 9748ea0 commit ce81418
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions projects/trails/src/Mirza/Trails/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Database.PostgreSQL.Simple

import Network.Wai (Middleware)
import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai.Middleware.Cors as CorsMiddleware

import Control.Exception (finally)
import Control.Monad (when)
Expand Down Expand Up @@ -51,11 +50,6 @@ defaultPortNumber = 8300
defaultDatabaseConnectionString :: ByteString
defaultDatabaseConnectionString = "dbname=devtrails"

corsOrigins :: [CorsMiddleware.Origin]
corsOrigins = [ "http://localhost:8080"
, "http://localhost:8300"
, "https://demo.mirza.d61.io"
]

--------------------------------------------------------------------------------
-- Command Line Options Data Types
Expand All @@ -77,8 +71,8 @@ data ServerOptionsTrails = ServerOptionsTrails
}

data RunServerOptions = RunServerOptions
{ runServerOptionsPortNumber :: Int
, runServerOptionsAutoMigrate :: Bool
{ runServerOptionsPortNumber :: Int
, runServerOptionsAutoMigrate :: Bool
}


Expand Down Expand Up @@ -140,17 +134,8 @@ initApplication ev =
pure $ serve api (server ev)


myCors :: Middleware
myCors = CorsMiddleware.cors (const $ Just policy)
where
policy = CorsMiddleware.simpleCorsResourcePolicy
{ CorsMiddleware.corsRequestHeaders = ["Content-Type", "Authorization"]
, CorsMiddleware.corsMethods = "PUT" : CorsMiddleware.simpleMethods
, CorsMiddleware.corsOrigins = Just (corsOrigins, True)
}

initMiddleware :: ServerOptionsTrails -> RunServerOptions -> IO Middleware
initMiddleware _ _ = pure myCors
initMiddleware _ _ = pure id

-- Implementation
server :: TrailsContext -> Server API
Expand Down

0 comments on commit ce81418

Please sign in to comment.