Skip to content

Commit

Permalink
Fix: empty config logspam, better startup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
robalb committed Dec 31, 2024
1 parent d40f126 commit 2c8aa50
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 118 deletions.
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tmp/
*.sqlite
main
stress/

2 changes: 1 addition & 1 deletion backend/docs/bruno_apispec/login.bru
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ post {

body:json {
{
"username": "antonio",
"username": "antonio2",
"password": "password"
}
}
Expand Down
4 changes: 2 additions & 2 deletions backend/docs/bruno_apispec/register.bru
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ post {

body:json {
{
"username": "antonio",
"username": "antonio2",
"password": "password",
"callsign": "US00ABC"
"callsign": "US02ABC"
}
}

Expand Down
98 changes: 0 additions & 98 deletions backend/home.html

This file was deleted.

8 changes: 6 additions & 2 deletions backend/internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ func ServeSessInit(
var userSettings Settings
userSettingsStr, ok := res.Settings.(string)
if !ok{
logger.Printf("ServeLogin: json settings type assert faied: %v", ok)
logger.Printf("ServeSessInit: json settings type assert faied: %v", ok)
} else if len(userSettingsStr) < 2 {
//There are not saved settings
} else if err := json.Unmarshal([]byte(userSettingsStr), &userSettings); err != nil{
logger.Printf("ServeLogin: json settings unmarshall faied: %v", err.Error())
logger.Printf("ServeSessInit: json settings unmarshall faied: %v", err.Error())
}else{
responseSettings = &userSettings
}
Expand Down Expand Up @@ -297,6 +299,8 @@ func ServeLogin(
userSettingsStr, ok := res.Settings.(string)
if !ok{
logger.Printf("ServeLogin: json settings type assert faied: %v", ok)
} else if len(userSettingsStr) < 2 {
//There are not saved settings
} else if err := json.Unmarshal([]byte(userSettingsStr), &userSettings); err != nil{
logger.Printf("ServeLogin: json settings unmarshall faied: %v", err.Error())
}else{
Expand Down
15 changes: 0 additions & 15 deletions backend/internal/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func AddRoutes(
dbWritePool *sql.DB,
/* Put here all the dependencies for middlewares and routers */
) {
rootMux.Get("/", serveHome)

ws := chi.NewRouter()
rootMux.Mount("/ws", ws)
ws.Use(middleware.RequireValidSession(tokenAuth))
Expand Down Expand Up @@ -84,19 +82,6 @@ func AddRoutes(
//TODO: move to dedicated file anything below this line
//---------

func serveHome(w http.ResponseWriter, r *http.Request) {
log.Println(r.URL)
if r.URL.Path != "/" {
http.Error(w, "Not found", http.StatusNotFound)
return
}
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
http.ServeFile(w, r, "home.html")
}

func serveTestCtx(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
select {
Expand Down
6 changes: 6 additions & 0 deletions backend/internal/server/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func Run(
logger.Printf("Failed to init app config: %v", err.Error())
return err
}
logger.Printf("Starting server with config: Host:'%s', Port:'%s', SqlitePath:'%s', secret:'%s[CENSORED]'",
config.Host,
config.Port,
config.SqlitePath,
config.Secret[0:5],
)
// Init JWT auth
tokenAuth := jwtauth.New("HS256", config.SecretBytes, nil)
// Init db
Expand Down

0 comments on commit 2c8aa50

Please sign in to comment.