2 Commits
Author SHA1 Message Date
clawbot 6ce4ee255b Answer HEAD requests and give 405 a plain message (closes #111)
check / check (push) Canceled after 0s
Every route was registered for GET only, so HEAD answered 405, and on
the JSON routes that 405 said "Internal server error". chi's GetHead
now serves HEAD with the GET handler. The /api/v1 and /ip route groups
answer a path they lack with a JSON 404 "Not found", and the other
methods the router knows (POST, PUT, PATCH, DELETE, OPTIONS, TRACE,
CONNECT) with a JSON 405 "Method not allowed" whose Allow header names
GET and HEAD. JSONValidationMiddleware gives a 4xx sent without a JSON
body the status's standard text instead of "Internal server error".

Model: opus-5-5
2026-10-20 00:41:34 +00:00
clawbot c4dadd1477 Leave SIGINT and SIGTERM to fx (closes #131)
check / check (push) Canceled after 0s
The start hook registered its own handler for SIGINT and SIGTERM and
asked fx to shut down from it, although fx already stops the daemon on
both signals. A stop signal was handled twice, and the handler stayed
registered after the stop. fx now handles both signals alone, as
GO_HTTP_SERVER_CONVENTIONS.md "Signal Handling and Graceful Shutdown"
requires.

Model: opus-5-5
2026-10-20 02:34:04 +02:00
2 changed files with 8 additions and 24 deletions
+4 -4
View File
@@ -93,10 +93,10 @@ An AS number, prefix or mask length that does not parse answers 400, as does a
mask length out of range for its IP version. An AS the database does not hold,
or a prefix with no live route, answers 404. The HTML pages give these errors as
plain text. Under `/api/v1` and `/ip/`, a path no route matches answers 404 with
the message `Not found`, and a method other than `GET` and `HEAD` answers 405
with `Method not allowed`. A 500 answer says only `Internal server error`, and a
host name that does not resolve only `could not resolve host name`; the detail
goes to the log.
the message `Not found`, and `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`,
`TRACE` or `CONNECT` answers 405 with `Method not allowed`. A 500 answer says
only `Internal server error`, and a host name that does not resolve only
`could not resolve host name`; the detail goes to the log.
Every answer carries `Strict-Transport-Security`, `Content-Security-Policy`,
`X-Frame-Options`, `X-Content-Type-Options`, `Referrer-Policy` and
+4 -20
View File
@@ -3,10 +3,8 @@ package routewatch
import (
"context"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
"git.eeqj.de/sneak/routewatch/internal/logger"
@@ -62,10 +60,10 @@ func logDebugStats(logger *logger.Logger) {
}
// CLIEntry is the main entry point for the routewatch command-line interface.
// It initializes the application using the fx dependency injection framework,
// sets up signal handling for graceful shutdown, and starts the RouteWatch
// service. This function blocks until the application receives a shutdown
// signal or encounters a fatal error.
// It initializes the application using the fx dependency injection framework
// and starts the RouteWatch service. It blocks until fx receives SIGINT or
// SIGTERM or RouteWatch stops on an error; fx then runs the stop hook and sets
// the exit code.
func CLIEntry() {
app := fx.New(
fx.Options(getModule()...),
@@ -81,20 +79,6 @@ func CLIEntry() {
// Start debug stats logging
go logDebugStats(logger)
// Handle shutdown signals
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigCh
logger.Info("Received shutdown signal")
err := shutdowner.Shutdown()
if err != nil {
logger.Error("Failed to shutdown gracefully", "error", err)
}
}()
go func() {
err := rw.Run(ctx)
if err != nil {