|
|
@ -130,12 +130,17 @@ func UploadHandler(w http.ResponseWriter, r *http.Request, pipes []pipelines.IPi |
|
|
|
logrus.Info("Pipeline routes registered successfully") |
|
|
|
} |
|
|
|
|
|
|
|
func RegisterRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { |
|
|
|
r.HandleFunc("/", IndexHandler).Methods("GET") |
|
|
|
r.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
func RegisterRoutes(r *mux.Router, appSettings settings.Settings, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { |
|
|
|
index := r.Methods(http.MethodGet).Subrouter() |
|
|
|
index.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
upload := r.Methods(http.MethodPost).Subrouter() |
|
|
|
upload.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
UploadHandler(w, r, pipelines, storageProvider) |
|
|
|
}).Methods("POST") |
|
|
|
r.HandleFunc("/pipelines/{pipeline}", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
}) |
|
|
|
|
|
|
|
pipeline := r.Methods(http.MethodGet).Subrouter() |
|
|
|
pipeline.HandleFunc("/pipelines/{pipeline}", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
for _, pipeline := range pipelines { |
|
|
|
if pipeline.GetSlug() == mux.Vars(r)["pipeline"] { |
|
|
|
PipelineHandler(pipeline, storageProvider, w, r) |
|
|
@ -144,7 +149,14 @@ func RegisterRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvi |
|
|
|
} |
|
|
|
|
|
|
|
w.WriteHeader(404) |
|
|
|
}).Methods("GET") |
|
|
|
}) |
|
|
|
|
|
|
|
if appSettings.Authentication.Enabled { |
|
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Authentication.Token) |
|
|
|
|
|
|
|
upload.Use(authMiddleware.Middleware) |
|
|
|
pipeline.Use(authMiddleware.Middleware) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func main() { |
|
|
@ -177,12 +189,6 @@ func main() { |
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
|
|
|
|
|
if appSettings.Authentication.Enabled { |
|
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Authentication.Token) |
|
|
|
|
|
|
|
r.Use(authMiddleware.Middleware) |
|
|
|
} |
|
|
|
|
|
|
|
if appSettings.RateLimiter.Enabled { |
|
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(appSettings.RateLimiter.RequestsPerMinute, appSettings.RateLimiter.AllowedBurst) |
|
|
|
if err != nil { |
|
|
@ -192,7 +198,7 @@ func main() { |
|
|
|
r.Use(rateLimiterMiddleware.Middleware) |
|
|
|
} |
|
|
|
|
|
|
|
RegisterRoutes(r, pipes, storageProvider) |
|
|
|
RegisterRoutes(r, appSettings, pipes, storageProvider) |
|
|
|
|
|
|
|
logrus.Info("Lithium started, listening for requests...") |
|
|
|
|
|
|
|