github.com/bitcubate/cryptojournal@v1.2.5-0.20171102134152-f578b3d788ab/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/bitcubate/cryptojournal/src/comments/actions"
     9  	"github.com/bitcubate/cryptojournal/src/lib/session"
    10  	"github.com/bitcubate/cryptojournal/src/stories/actions"
    11  	"github.com/bitcubate/cryptojournal/src/users/actions"
    12  )
    13  
    14  // SetupRoutes creates a new router and adds the routes for this app to it.
    15  func SetupRoutes() *mux.Mux {
    16  
    17  	router := mux.New()
    18  	mux.SetDefault(router)
    19  
    20  	// Add the home page route
    21  	router.Get("/", storyactions.HandleHome)
    22  
    23  	// Add a route to handle static files
    24  	router.Get("/favicon.ico", fileHandler)
    25  	router.Get("/files/{path:.*}", fileHandler)
    26  	router.Get("/assets/{path:.*}", fileHandler)
    27  
    28  	// Resource Routes
    29  
    30  	// Add story routes
    31  	router.Get("/index{format:(.xml)?}", storyactions.HandleIndex)
    32  	router.Get("/stories/create", storyactions.HandleCreateShow)
    33  	router.Post("/stories/create", storyactions.HandleCreate)
    34  	router.Get("/stories/code{format:(.xml)?}", storyactions.HandleListCode)
    35  	router.Get("/stories/upvoted{format:(.xml)?}", storyactions.HandleListUpvoted)
    36  	router.Get("/stories/{id:[0-9]+}/update", storyactions.HandleUpdateShow)
    37  	router.Post("/stories/{id:[0-9]+}/update", storyactions.HandleUpdate)
    38  	router.Post("/stories/{id:[0-9]+}/destroy", storyactions.HandleDestroy)
    39  	router.Post("/stories/{id:[0-9]+}/upvote", storyactions.HandleUpvote)
    40  	router.Post("/stories/{id:[0-9]+}/downvote", storyactions.HandleDownvote)
    41  	router.Post("/stories/{id:[0-9]+}/flag", storyactions.HandleFlag)
    42  	router.Get("/stories/{id:[0-9]+}", storyactions.HandleShow)
    43  	router.Get("/stories{format:(.xml)?}", storyactions.HandleIndex)
    44  	router.Get("/sitemap.xml", storyactions.HandleSiteMap)
    45  
    46  	router.Get("/comments", commentactions.HandleIndex)
    47  	router.Get("/comments/create", commentactions.HandleCreateShow)
    48  	router.Post("/comments/create", commentactions.HandleCreate)
    49  	router.Get("/comments/{id:[0-9]+}/update", commentactions.HandleUpdateShow)
    50  	router.Post("/comments/{id:[0-9]+}/update", commentactions.HandleUpdate)
    51  	router.Post("/comments/{id:[0-9]+}/destroy", commentactions.HandleDestroy)
    52  	router.Post("/comments/{id:[0-9]+}/upvote", commentactions.HandleUpvote)
    53  	router.Post("/comments/{id:[0-9]+}/downvote", commentactions.HandleDownvote)
    54  	router.Post("/comments/{id:[0-9]+}/flag", commentactions.HandleFlag)
    55  	router.Get("/comments/{id:[0-9]+}", commentactions.HandleShow)
    56  
    57  	router.Get("/users", useractions.HandleIndex)
    58  	router.Get("/users/create", useractions.HandleCreateShow)
    59  	router.Post("/users/create", useractions.HandleCreate)
    60  	router.Get("/users/{id:[0-9]+}/update", useractions.HandleUpdateShow)
    61  	router.Post("/users/{id:[0-9]+}/update", useractions.HandleUpdate)
    62  	router.Post("/users/{id:[0-9]+}/destroy", useractions.HandleDestroy)
    63  	router.Get("/users/{id:[0-9]+}", useractions.HandleShow)
    64  	router.Get("/u/{name:.*}", useractions.HandleShowName)
    65  	router.Get("/users/login", useractions.HandleLoginShow)
    66  	router.Post("/users/login", useractions.HandleLogin)
    67  	router.Post("/users/logout", useractions.HandleLogout)
    68  
    69  	// Set the default file handler
    70  	router.FileHandler = fileHandler
    71  	router.ErrorHandler = errHandler
    72  
    73  	// Add middleware
    74  	router.AddMiddleware(log.Middleware)
    75  	router.AddMiddleware(session.Middleware)
    76  
    77  	return router
    78  }