github.com/titpetric/pendulum@v0.1.180207-1512.0.20180514135826-1f399445df57/cmd/pendulum/routes.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/go-chi/chi"
     5  	"github.com/go-chi/chi/middleware"
     6  	"github.com/go-chi/cors"
     7  )
     8  
     9  // MountRoutes will register API routes
    10  func MountRoutes(r chi.Router, api *API) {
    11  	// CORS for local development...
    12  	cors := cors.New(cors.Options{
    13  		AllowedOrigins:   []string{"*"},
    14  		AllowedMethods:   []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"},
    15  		AllowedHeaders:   []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
    16  		AllowCredentials: true,
    17  		MaxAge:           300, // Maximum value not ignored by any of major browsers
    18  	})
    19  	r.Use(cors.Handler)
    20  	r.Use(middleware.Logger)
    21  
    22  	r.Route("/api", func(r chi.Router) {
    23  		// List all jobs
    24  		r.Get("/list/*", api.ListHandler)
    25  		r.Get("/read/*", api.ReadHandler)
    26  		r.Post("/store/*", api.StoreHandler)
    27  	})
    28  
    29  	// read from local storage
    30  	r.Get("/contents/*", api.Contents)
    31  
    32  	// served from bindata assets
    33  	r.Get("/*", api.Assets)
    34  }