Skip to content

Commit

Permalink
refactor: change redirect
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Hivert <hivert.is.coming@gmail.com>
  • Loading branch information
ghivert committed May 6, 2024
1 parent 28587f5 commit e89475e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/backend/request.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import wisp.{type Request}
pub fn is_json_request(req: Request) -> Bool {
request.get_header(req, "accept")
|> result.map(fn(content) { content == "application/json" })
|> result.unwrap(False)
|> result.unwrap(True)
}
9 changes: 4 additions & 5 deletions apps/backend/src/backend/web.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ pub fn foundations(req: Request, handler: Handler) -> Response {
}

pub fn reroute_non_json_request(req: Request, handler: Handler) -> Response {
case req.method, request.is_json_request(req), config.is_dev() {
http.Get, True, _ -> handler(req)
http.Get, False, True -> wisp.redirect("http://localhost:5173")
http.Get, False, False -> wisp.ok()
_, _, _ -> handler(req)
case req.method, request.is_json_request(req) {
http.Get, True -> handler(req)
http.Get, False -> wisp.ok()
_, _ -> handler(req)
}
}

Expand Down
1 change: 0 additions & 1 deletion apps/frontend/src/frontend.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import data/model.{type Model}
import data/msg.{type Msg}
import frontend/view
import gleam/io
import lustre
import lustre/effect
import lustre/update
Expand Down

0 comments on commit e89475e

Please sign in to comment.