32 lines
795 B
Go
32 lines
795 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"github.com/labstack/echo/v4"
|
||
|
"github.com/labstack/echo/v4/middleware"
|
||
|
)
|
||
|
|
||
|
type Options struct {
|
||
|
BindAddr string
|
||
|
Timeout time.Duration
|
||
|
}
|
||
|
|
||
|
func Start(opts Options) error {
|
||
|
e := echo.New()
|
||
|
e.Use(middleware.Logger())
|
||
|
e.Use(middleware.Recover())
|
||
|
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{Timeout: opts.Timeout}))
|
||
|
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||
|
AllowOrigins: []string{"http://localhost:3000"},
|
||
|
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
|
||
|
}))
|
||
|
|
||
|
e.GET("/api/media_sets/:id", getMediaSet)
|
||
|
e.GET("/api/media_sets/:id/thumbnails", getThumbnails)
|
||
|
e.GET("/api/media_sets/:id/video", getVideo)
|
||
|
e.GET("/api/media_sets/:id/peaks", getPeaks)
|
||
|
|
||
|
return e.Start(opts.BindAddr)
|
||
|
}
|