2022-08-16 16:35:45 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (app *application) routes() *httprouter.Router {
|
|
|
|
router := httprouter.New()
|
|
|
|
|
2022-08-17 23:14:05 +02:00
|
|
|
router.NotFound = http.HandlerFunc(app.notFoundResponse)
|
|
|
|
router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowedResponse)
|
|
|
|
|
2022-08-18 22:01:48 +02:00
|
|
|
// cors.Default().Handler(router)
|
2022-08-16 16:35:45 +02:00
|
|
|
router.HandlerFunc(http.MethodGet, "/v1/commands/:name", app.showCommandHandler)
|
2022-08-17 15:32:42 +02:00
|
|
|
router.HandlerFunc(http.MethodPost, "/v1/commands", app.createCommandHandler)
|
2022-08-17 20:57:25 +02:00
|
|
|
router.HandlerFunc(http.MethodPatch, "/v1/commands/:name", app.updateCommandHandler)
|
2022-08-17 18:07:50 +02:00
|
|
|
router.HandlerFunc(http.MethodDelete, "/v1/commands/:name", app.deleteCommandHandler)
|
2022-08-18 22:01:48 +02:00
|
|
|
|
2022-08-16 16:35:45 +02:00
|
|
|
return router
|
|
|
|
}
|
2022-08-18 22:01:48 +02:00
|
|
|
|
|
|
|
func MiddleCORS(next httprouter.Handle) httprouter.Handle {
|
|
|
|
return func(w http.ResponseWriter,
|
|
|
|
r *http.Request, ps httprouter.Params) {
|
|
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
|
next(w, r, ps)
|
|
|
|
}
|
|
|
|
}
|