github.com/saadullahsaeed/fragmenta-cms@v1.5.4/src/app/routes.go (about)

     1  package app
     2  
     3  import (
     4  	"github.com/fragmenta/mux"
     5  	"github.com/fragmenta/server/log"
     6  
     7  	// Resource Actions
     8  	"github.com/fragmenta/fragmenta-cms/src/images/actions"
     9  	"github.com/fragmenta/fragmenta-cms/src/lib/session"
    10  	"github.com/fragmenta/fragmenta-cms/src/pages/actions"
    11  	"github.com/fragmenta/fragmenta-cms/src/posts/actions"
    12  	"github.com/fragmenta/fragmenta-cms/src/redirects/actions"
    13  	"github.com/fragmenta/fragmenta-cms/src/tags/actions"
    14  	"github.com/fragmenta/fragmenta-cms/src/users/actions"
    15  )
    16  
    17  // SetupRoutes creates a new router and adds the routes for this app to it.
    18  func SetupRoutes() *mux.Mux {
    19  
    20  	router := mux.New()
    21  	mux.SetDefault(router)
    22  
    23  	// Set the default file handler
    24  	router.FileHandler = fileHandler
    25  	router.ErrorHandler = errHandler
    26  
    27  	// Add middleware
    28  	router.AddMiddleware(log.Middleware)
    29  	router.AddMiddleware(session.Middleware)
    30  
    31  	// Add the home page route
    32  	router.Get("/", pageactions.HandleShowHome)
    33  
    34  	// Add a route to handle static files
    35  	router.Add("/favicon.ico", fileHandler)
    36  	router.Add("/files/{path:.*}", fileHandler)
    37  	router.Add("/assets/{path:.*}", fileHandler)
    38  
    39  	// Resource Routes
    40  
    41  	router.Get("/redirects", redirectactions.HandleIndex)
    42  	router.Get("/redirects/create", redirectactions.HandleCreateShow)
    43  	router.Post("/redirects/create", redirectactions.HandleCreate)
    44  	router.Get("/redirects/{id:[0-9]+}/update", redirectactions.HandleUpdateShow)
    45  	router.Post("/redirects/{id:[0-9]+}/update", redirectactions.HandleUpdate)
    46  	router.Post("/redirects/{id:[0-9]+}/destroy", redirectactions.HandleDestroy)
    47  	router.Get("/redirects/{id:[0-9]+}", redirectactions.HandleShow)
    48  
    49  	router.Get("/pages", pageactions.HandleIndex)
    50  	router.Get("/pages/create", pageactions.HandleCreateShow)
    51  	router.Post("/pages/create", pageactions.HandleCreate)
    52  	router.Get("/pages/{id:[0-9]+}/update", pageactions.HandleUpdateShow)
    53  	router.Post("/pages/{id:[0-9]+}/update", pageactions.HandleUpdate)
    54  	router.Post("/pages/{id:[0-9]+}/destroy", pageactions.HandleDestroy)
    55  	router.Get("/pages/{id:[0-9]+}", pageactions.HandleShow)
    56  	router.Get("/fragmenta/setup", pageactions.HandleSetupShow)
    57  	router.Post("/fragmenta/setup", pageactions.HandleSetup)
    58  
    59  	router.Get("/images", imageactions.HandleIndex)
    60  	router.Get("/images/create", imageactions.HandleCreateShow)
    61  	router.Post("/images/create", imageactions.HandleCreate)
    62  	router.Get("/images/{id:[0-9]+}/update", imageactions.HandleUpdateShow)
    63  	router.Post("/images/{id:[0-9]+}/update", imageactions.HandleUpdate)
    64  	router.Post("/images/{id:[0-9]+}/destroy", imageactions.HandleDestroy)
    65  	router.Get("/images/{id:[0-9]+}", imageactions.HandleShow)
    66  
    67  	router.Get("/posts", postactions.HandleIndex)
    68  	router.Get("/posts/create", postactions.HandleCreateShow)
    69  	router.Post("/posts/create", postactions.HandleCreate)
    70  	router.Get("/posts/{id:[0-9]+}/update", postactions.HandleUpdateShow)
    71  	router.Post("/posts/{id:[0-9]+}/update", postactions.HandleUpdate)
    72  	router.Post("/posts/{id:[0-9]+}/destroy", postactions.HandleDestroy)
    73  	router.Get("/posts/{id:[0-9]+}", postactions.HandleShow)
    74  	router.Get("/blog", postactions.HandleShowBlog)
    75  	router.Get("/blog/{id:[0-9]+}", postactions.HandleShow)
    76  
    77  	router.Get("/tags", tagactions.HandleIndex)
    78  	router.Get("/tags/create", tagactions.HandleCreateShow)
    79  	router.Post("/tags/create", tagactions.HandleCreate)
    80  	router.Get("/tags/{id:[0-9]+}/update", tagactions.HandleUpdateShow)
    81  	router.Post("/tags/{id:[0-9]+}/update", tagactions.HandleUpdate)
    82  	router.Post("/tags/{id:[0-9]+}/destroy", tagactions.HandleDestroy)
    83  	router.Get("/tags/{id:[0-9]+}", tagactions.HandleShow)
    84  
    85  	router.Get("/users", useractions.HandleIndex)
    86  	router.Get("/users/create", useractions.HandleCreateShow)
    87  	router.Post("/users/create", useractions.HandleCreate)
    88  	router.Get("/users/login", useractions.HandleLoginShow)
    89  	router.Post("/users/login", useractions.HandleLogin)
    90  	router.Post("/users/logout", useractions.HandleLogout)
    91  	router.Get("/users/{id:[0-9]+}/update", useractions.HandleUpdateShow)
    92  	router.Post("/users/{id:[0-9]+}/update", useractions.HandleUpdate)
    93  	router.Post("/users/{id:[0-9]+}/destroy", useractions.HandleDestroy)
    94  	router.Get("/users/{id:[0-9]+}", useractions.HandleShow)
    95  
    96  	// Add catch-all for custom page routes - this must be evaluated last.
    97  	router.Get("/{path:.+}", pageactions.HandleShowPath)
    98  
    99  	return router
   100  }