Return 404 on unmatched routes (#1201)

This commit is contained in:
dnaq 2023-03-03 17:14:30 +01:00 committed by GitHub
parent f49930c514
commit a82a603db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

5
app.go
View File

@ -521,7 +521,7 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router {
apiRouter.Use(h.httpAuthenticationMiddleware) apiRouter.Use(h.httpAuthenticationMiddleware)
apiRouter.PathPrefix("/v1/").HandlerFunc(grpcMux.ServeHTTP) apiRouter.PathPrefix("/v1/").HandlerFunc(grpcMux.ServeHTTP)
router.PathPrefix("/").HandlerFunc(stdoutHandler) router.PathPrefix("/").HandlerFunc(notFoundHandler)
return router return router
} }
@ -957,7 +957,7 @@ func (h *Headscale) getLastStateChange(users ...User) time.Time {
} }
} }
func stdoutHandler( func notFoundHandler(
writer http.ResponseWriter, writer http.ResponseWriter,
req *http.Request, req *http.Request,
) { ) {
@ -969,6 +969,7 @@ func stdoutHandler(
Interface("url", req.URL). Interface("url", req.URL).
Bytes("body", body). Bytes("body", body).
Msg("Request did not match") Msg("Request did not match")
writer.WriteHeader(http.StatusNotFound)
} }
func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) { func readOrCreatePrivateKey(path string) (*key.MachinePrivate, error) {