2024-11-11 17:34:37 +08:00
|
|
|
package http_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2024-11-11 18:47:15 +08:00
|
|
|
"github.com/Vomitblood/cspj-application/server/internal/db"
|
2024-11-11 17:34:37 +08:00
|
|
|
"github.com/Vomitblood/cspj-application/server/internal/sql_injection"
|
|
|
|
)
|
|
|
|
|
2024-11-11 20:37:45 +08:00
|
|
|
func healthCheck(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte(`{"status": "ok"}`))
|
|
|
|
}
|
|
|
|
|
2024-11-11 17:34:37 +08:00
|
|
|
// setup the http server
|
|
|
|
func ServeApi() {
|
2024-11-11 20:37:45 +08:00
|
|
|
http.HandleFunc("/health", healthCheck)
|
2024-12-12 10:51:51 +08:00
|
|
|
http.HandleFunc("/health-db", db.DbHealthCheck)
|
2024-11-11 18:47:15 +08:00
|
|
|
http.HandleFunc("/setup-demo-db", db.SetupDemoDb)
|
|
|
|
http.HandleFunc("/nuke-db", db.NukeDb)
|
|
|
|
http.HandleFunc("/fetch-all-users", db.FetchAllUsers)
|
2024-11-11 17:34:37 +08:00
|
|
|
http.HandleFunc("/execute-sql", sql_injection.ExecuteSql)
|
2024-11-12 11:53:55 +08:00
|
|
|
http.HandleFunc("/login-sql", sql_injection.LoginSql)
|
2024-11-11 17:34:37 +08:00
|
|
|
http.HandleFunc("/secure-execute-sql", sql_injection.SecureExecuteSql)
|
2025-01-14 02:39:24 +08:00
|
|
|
http.HandleFunc("/register-sql", sql_injection.RegisterSql)
|
2024-11-12 11:53:55 +08:00
|
|
|
http.HandleFunc("/secure-login-sql", sql_injection.SecureLoginSql)
|
2024-11-11 18:47:15 +08:00
|
|
|
http.HandleFunc("/secure-get-user", sql_injection.SecureGetUser)
|
2024-11-11 20:37:45 +08:00
|
|
|
log.Println("Server is running on http://localhost:5000")
|
|
|
|
if err := http.ListenAndServe(":5000", nil); err != nil {
|
2024-11-11 17:34:37 +08:00
|
|
|
log.Fatalf("Failed to start server: %v", err)
|
|
|
|
}
|
|
|
|
}
|