Skip to content

Commit d6b5a77

Browse files
committed
Fix htmx redirection
1 parent d17f187 commit d6b5a77

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ setup: tailwindcss-init
3232

3333
tailwindcss-init:
3434
npm i &&\
35-
npx tailwindcss build -i assets/css/style.css -o assets/css/tailwind.css -m
35+
npx tailwindcss@3.4.1 build -i assets/css/style.css -o assets/css/tailwind.css -m
3636

3737
tailwindcss-build:
38-
npx tailwindcss build -i assets/css/style.css -o assets/css/tailwind.css -m
38+
npx tailwindcss@3.4.1 build -i assets/css/style.css -o assets/css/tailwind.css -m
3939

4040
clean:
4141
rm -rf *.o *.so $(BINARY_NAMR)

src/middlewares.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ result *check_token_and_return_user(const char *token);
55

66
int handle_redirect(const struct _u_request *req, struct _u_response *res,
77
const char *url) {
8+
char *is_htmx = (char *)u_map_get(req->map_header, "HX-Request");
9+
if (is_htmx != NULL && strcmp(is_htmx, "true") == 0) {
10+
ulfius_set_response_properties(
11+
res,
12+
U_OPT_HEADER_PARAMETER, "HX-Retarget", "#container",
13+
U_OPT_HEADER_PARAMETER, "HX-Redirect", url,
14+
U_OPT_HEADER_PARAMETER, "HX-Push-Url", url,
15+
U_OPT_NONE);
16+
17+
return U_CALLBACK_CONTINUE;
18+
}
19+
820
char *body = (char *)malloc(strlen(url) + 26);
921
sprintf(body, "<a href=\"%s\">301</a>.\n", url);
1022
ulfius_set_response_properties(res, U_OPT_STATUS, 301, U_OPT_STRING_BODY,

views/user_settings.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
class="flex items-center gap-2 w-full active:bg-[rgb(150,150,150)] hover:bg-[rgb(170,170,170)] px-2 py-1 border-2 border-neutral-100 border-r-neutral-700 border-b-neutral-700 active:border-neutral-700 active:border-r-neutral-100 active:border-b-neutral-100 bg-[rgb(204,204,204)] font-bold font-mono"
8383
hx-delete="/api/todos/all-finished"
8484
hx-swap="none"
85-
hx-confirm="Are you sure you want to remove all your finished todos? (Not implemented yet)"
85+
hx-confirm="Are you sure you want to remove all your finished todos?"
8686
title="Remove all finished todos"
8787
>
8888
<img
@@ -101,7 +101,7 @@
101101
hx-confirm="Are you sure you want to delete your account?"
102102
hx-delete="/api/user/delete-me"
103103
class="flex items-center gap-2 active:bg-red-600 w-full hover:bg-red-600 px-2 py-1 border-2 border-red-300 border-r-red-800 border-b-red-800 active:border-red-800 active:border-r-red-300 active:border-b-red-300 bg-red-500 font-bold font-mono text-white"
104-
title="Delete account (no going back!) (Not implemented yet)"
104+
title="Delete account (no going back!)"
105105
>
106106
<img
107107
class="inline-block w-6 aspect-square object-center object-contain"

0 commit comments

Comments
 (0)