package npmregserver import ( "gosimplenpm/config" "gosimplenpm/handler" "gosimplenpm/middlewares" "net/http" "github.com/gorilla/mux" "github.com/sirupsen/logrus" ) type Application struct { Logger *logrus.Logger Conf config.Config } func (app *Application) Routes() *mux.Router { // Need to use UseEncodedPath as shown here https://github.com/gorilla/mux/blob/master/mux.go#L269 m := mux.NewRouter().StrictSlash(true).UseEncodedPath() m.Use(middlewares.LogMiddleware(app.Logger)) // main handler m.HandleFunc("/{name}", handler.Get).Methods("GET") m.HandleFunc("/{name}", middlewares.AuthMiddleware(app.Conf)(handler.Publish)).Methods("PUT") // tar handlers m.HandleFunc("/{name}/-/{tar}", handler.Tar).Methods("GET") // tag handlers m.HandleFunc("/-/package/{name}/dist-tags/{tag}", middlewares.AuthMiddleware(app.Conf)(handler.DistTagDelete(app.Logger))).Methods("DELETE") m.HandleFunc("/-/package/{name}/dist-tags/{tag}", middlewares.AuthMiddleware(app.Conf)(handler.DistTagPut(app.Logger))).Methods("PUT") m.HandleFunc("/-/package/{name}/dist-tags", handler.DistTagGet(app.Logger)).Methods("GET") m.NotFoundHandler = http.HandlerFunc(handler.NotFound) return m }