package Api
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func loggingMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
log.Printf(
|
|
"%s %s %s, Content Length: %d",
|
|
r.RemoteAddr,
|
|
r.Method,
|
|
r.RequestURI,
|
|
r.ContentLength,
|
|
)
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func authenticationMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var (
|
|
//userSession Auth.Session
|
|
//err error
|
|
)
|
|
|
|
http.Error(w, "Forbidden", http.StatusUnauthorized)
|
|
return
|
|
|
|
/**
|
|
userSession, err = Auth.CheckCookie(r)
|
|
|
|
if err != nil {
|
|
http.Error(w, "Forbidden", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
log.Printf(
|
|
"Authenticated user: %s (%s)",
|
|
userSession.Email,
|
|
userSession.UserID,
|
|
)
|
|
|
|
next.ServeHTTP(w, r)
|
|
*/
|
|
})
|
|
}
|
|
|
|
func InitApiEndpoints(router *mux.Router) {
|
|
var (
|
|
api *mux.Router
|
|
adminApi *mux.Router
|
|
)
|
|
|
|
log.Println("Initializing API routes...")
|
|
|
|
api = router.PathPrefix("/api/v1/").Subrouter()
|
|
|
|
api.Use(loggingMiddleware)
|
|
|
|
// Define routes for authentication
|
|
api.HandleFunc("/signup", Auth.Signup).Methods("POST")
|
|
// api.HandleFunc("/login", Auth.Login).Methods("POST")
|
|
// api.HandleFunc("/logout", Auth.Logout).Methods("GET")
|
|
|
|
adminApi = api.PathPrefix("/message/").Subrouter()
|
|
|
|
adminApi.Use(authenticationMiddleware)
|
|
}
|