aboutsummaryrefslogtreecommitdiff
path: root/src/request.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'src/request.gleam')
-rw-r--r--src/request.gleam15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/request.gleam b/src/request.gleam
index c66e66d..5ef74c1 100644
--- a/src/request.gleam
+++ b/src/request.gleam
@@ -5,7 +5,6 @@ import gleam/json
import gleam/list
import gleam/string
import gleam/string_builder
-import simplifile
import svg
import wisp
@@ -19,13 +18,14 @@ fn middleware(request, handle) {
handle(request)
}
-pub fn handle(request, connection, image_cache) {
+pub fn handle(request, connection, image_cache, index_html) {
use _ <- middleware(request)
case wisp.path_segments(request) {
[] ->
- case simplifile.read("index.html") {
- Ok(content) ->
+ case index_html {
+ "" -> wisp.not_found()
+ content ->
wisp.html_response(
string_builder.from_string(
string.replace(
@@ -39,24 +39,25 @@ pub fn handle(request, connection, image_cache) {
),
200,
)
- Error(_) -> wisp.not_found()
}
["heart-beat"] ->
wisp.html_response(string_builder.from_string("alive"), 200)
["get", "@" <> name] -> {
case database.get_counter(connection, name) {
Ok(counter) -> {
+ let query = wisp.get_query(request)
+
wisp.ok()
|> wisp.set_header("Content-Type", "image/svg+xml")
|> wisp.string_body(
svg.xml(
image_cache,
- case list.key_find(wisp.get_query(request), "theme") {
+ case list.key_find(query, "theme") {
Ok(theme) -> theme
_ -> "asoul"
},
counter.num,
- case list.key_find(wisp.get_query(request), "padding") {
+ case list.key_find(query, "padding") {
Ok(padding) ->
case int.parse(padding) {
Ok(n) -> n