This commit is contained in:
Erik Winter 2024-01-20 13:32:46 +01:00
parent 7b5bc5f349
commit 4d45b41645
2 changed files with 2 additions and 1 deletions

View File

@ -42,6 +42,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rec.Header().Add("Content-Type", "application/json")
// authenticate
logger.Info("authenticating", "key", r.Header.Get("Authorization"), "apiKey", s.apiKey)
if key := r.Header.Get("Authorization"); s.apiKey != "localOnly" && key != s.apiKey {
Error(rec, http.StatusUnauthorized, "unauthorized", fmt.Errorf("invalid api key"), logger)
logger.Info("unauthorized", "key", key)

View File

@ -24,7 +24,7 @@ var (
func main() {
flag.Parse()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Info("starting server", "port", *port, "dbPath", *dbPath, "apiKey", *apiKey)
logger.Info("starting server", "port", *port, "dbPath", *dbPath)
db, err := moviestore.NewSQLite(*dbPath)
if err != nil {