Skip to content

Commit 47f2646

Browse files
committed
hmr wasnt working for catch all route
1 parent 10371ee commit 47f2646

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

core.sh

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ declare -A COOKIES
1111

1212
[[ -f 'config.sh' ]] && source config.sh
1313

14-
if [[ "${DEV:-true}" == true ]]; then
15-
USE_HMR="$(which inotifywait)"
16-
fi
17-
1814
debug() {
1915
printf "%s\n" "$@" 1>&2
2016
}
2117

18+
if [[ "${DEV:-true}" == true ]]; then
19+
USE_HMR="$(which inotifywait)"
20+
fi
21+
2222
header() {
2323
printf "%s: %s\r\n" "$1" "$2"
2424
}
@@ -355,41 +355,39 @@ writeHttpResponse() {
355355
return
356356
fi
357357
matchRoute "$REQUEST_PATH"
358-
if [[ -z "$ROUTE_SCRIPT" ]]; then
359-
if [[ ! -z "$USE_HMR" ]] && [[ "$REQUEST_PATH" == "/hmr" ]]; then
360-
if [[ "$REQUEST_METHOD" == "POST" ]]; then
361-
respond 204 OK
362-
header HX-Redirect "${HTTP_HEADERS[HX-Current-Url]}"
363-
end_headers
364-
return
365-
fi
366-
respond 200 OK
367-
header Content-Type "text/event-stream"
358+
if [[ ! -z "$USE_HMR" ]] && [[ "$REQUEST_PATH" == "/hmr" ]]; then
359+
if [[ "$REQUEST_METHOD" == "POST" ]]; then
360+
respond 204 OK
361+
header HX-Redirect "${HTTP_HEADERS[HX-Current-Url]}"
368362
end_headers
369-
output() {
370-
while true; do
371-
inotifywait -e MODIFY -r pages &> /dev/null
372-
event "reload"
373-
done
374-
}
375-
output &
376-
PID=$!
363+
return
364+
fi
365+
respond 200 OK
366+
header Content-Type "text/event-stream"
367+
end_headers
368+
output() {
369+
while true; do
370+
inotifywait -e MODIFY -r pages &> /dev/null
371+
event "reload"
372+
done
373+
}
374+
output &
375+
PID=$!
377376

378377

379-
while IFS= read -r line; do
380-
:
381-
done
378+
while IFS= read -r line; do
379+
:
380+
done
382381

383-
kill -9 $PID &>/dev/null
384-
wait $PID 2>/dev/null
382+
kill -9 $PID &>/dev/null
383+
wait $PID 2>/dev/null
385384

386-
return
387-
else
388-
debug "404 no match found"
389-
respond 404 Not Found
390-
end_headers
391-
return
392-
fi
385+
return
386+
elif [[ -z "$ROUTE_SCRIPT" ]]; then
387+
debug "404 no match found"
388+
respond 404 Not Found
389+
end_headers
390+
return
393391
fi
394392

395393
if directive_test=$(head -1 "pages/${ROUTE_SCRIPT}"); then

0 commit comments

Comments
 (0)