preview.go 512 B

1234567891011121314151617181920212223
  1. package web
  2. import (
  3. "html/template"
  4. "net/http"
  5. "strings"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func makePreviewer(renderer *template.Template) gin.HandlerFunc {
  9. const prefix = "storybook-preview"
  10. return func(c *gin.Context) {
  11. c.Header("Access-Control-Allow-Origin", "*")
  12. u := c.Request.URL
  13. p := strings.Replace(u.EscapedPath(), "/"+prefix+"/", "", 1)
  14. splitPath := strings.Split(p, "/")
  15. name, _ := splitPath[0], splitPath[1]
  16. q := u.Query()
  17. fl := q["flashes"]
  18. c.HTML(http.StatusOK, name, fl)
  19. }
  20. }