wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam

:lock: allow cors again

+28 -24
+1 -1
src/app/supervision_tree.gleam
··· 34 34 } 35 35 } 36 36 37 - let bind_to = case ctx.env, envoy.get("SIGO_HOST") { 37 + let bind_to = case ctx.env, envoy.get("SIGO_BIND") { 38 38 context.Production, _ -> "0.0.0.0" 39 39 context.Dev, Ok(bind) -> bind 40 40 context.Dev, _ -> "localhost"
+27 -23
src/app/web.gleam
··· 16 16 //// - Static file serving from `/static` path 17 17 18 18 import app/web/context 19 + import cors_builder as cors 20 + import envoy 19 21 import gleam/dynamic/decode 22 + import gleam/http 20 23 import gleam/json 21 24 import gleam/list 25 + import gleam/result 22 26 import gleam/string 23 27 import glight 24 28 import pog 25 29 import wisp 26 - 27 - // import cors_builder as cors 28 - // import gleam/http 29 30 30 31 /// Middleware that runs before every request. 31 32 /// It sets up the request, and then calls the next handler. ··· 40 41 use <- wisp.log_request(request) 41 42 use <- wisp.rescue_crashes() 42 43 use request <- wisp.handle_head(request) 43 - // use request <- cors.wisp_middleware(request, cors_config(ctx)) 44 + use request <- cors.wisp_middleware(request, cors_config(ctx)) 44 45 45 46 use <- wisp.serve_static(request, under: path, from: ctx.static_directory) 46 47 handler(request) ··· 65 66 priv_directory <> "/log" 66 67 } 67 68 68 - // fn cors_config(ctx: context.Context) -> cors.Cors { 69 - // let config = 70 - // cors.new() 71 - // |> cors.allow_origin("https://sigo.cbpm.vercel.app") 72 - // |> cors.allow_method(http.Get) 73 - // |> cors.allow_method(http.Post) 74 - // |> cors.allow_method(http.Put) 75 - // |> cors.allow_method(http.Delete) 76 - // |> cors.allow_method(http.Options) 77 - // |> cors.allow_header("authorization") 78 - // |> cors.allow_header("content-type") 79 - // |> cors.allow_header("origin") 80 - // |> cors.allow_credentials() 81 - // 82 - // case ctx.env { 83 - // context.Dev -> cors.allow_all_origins(config) 84 - // context.Production -> config 85 - // } 86 - // } 69 + fn cors_config(ctx: context.Context) -> cors.Cors { 70 + let config = 71 + cors.new() 72 + |> cors.allow_origin("https://sigo.cbpm.vercel.app") 73 + |> cors.allow_method(http.Get) 74 + |> cors.allow_method(http.Post) 75 + |> cors.allow_method(http.Put) 76 + |> cors.allow_method(http.Delete) 77 + |> cors.allow_method(http.Options) 78 + |> cors.allow_header("authorization") 79 + |> cors.allow_header("content-type") 80 + |> cors.allow_header("origin") 81 + |> cors.allow_credentials() 82 + 83 + case ctx.env { 84 + context.Production -> config 85 + context.Dev -> 86 + envoy.get("SIGO_ALLOW") 87 + |> result.unwrap("http://localhost:8081") 88 + |> cors.allow_origin(config, _) 89 + } 90 + } 87 91 88 92 pub fn handle_decode_error( 89 93 decode_errors: List(decode.DecodeError),