Added CORS-Header in Go #8

Merged
Alpha merged 3 commits from 123niel/tsviewer:master into master 2019-02-07 14:02:28 +00:00
2 changed files with 12 additions and 5 deletions

View file

@ -8,7 +8,7 @@ I´m a sick Fuck i like the sick F09ck
```bash ```bash
docker build -t name/cont:ver . docker build -t name/cont:ver .
docker run -e TS3_IP="0.0.0.0", TS3_PW="f3gWdOU3", WEB_PORT="8080" -d -p 8080:8080 name/cont:ver docker run -e TS3_IP="<SERVER-IP>" -e TS3_PW="<SERVER-ADMIN_PW>" -e WEB_PORT="8080" -d -p 8080:8080 name/cont:ver
``` ```
ENV: ENV:
```Docker ```Docker
@ -50,7 +50,7 @@ The config file is generated automatically on first startup.
## URL-Parameter ## URL-Parameter
| Name | Type | Description | | Name | Type | Description |
| ---------- | -------- | ------------------------ | | ---------- | ------ | ------------------------ |
| `pretty` | `bool` | pretty-prints JSON | | `pretty` | `bool` | pretty-prints JSON |
| `envelope` | `bool` | wraps JSON in data array | | `envelope` | `bool` | wraps JSON in data array |

View file

@ -16,16 +16,23 @@ import (
"git.cliffbreak.de/Cliffbreak/tsviewer/service" "git.cliffbreak.de/Cliffbreak/tsviewer/service"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/go-chi/chi/middleware" "github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
) )
func Routes(s service.Service, t template.Template) *chi.Mux { func Routes(s service.Service, t template.Template) *chi.Mux {
router := chi.NewRouter() router := chi.NewRouter()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"Get"},
})
router.Use( router.Use(
middleware.Logger, middleware.Logger,
middleware.Timeout(5*time.Second), middleware.Timeout(5*time.Second),
middleware.DefaultCompress, middleware.DefaultCompress,
middleware.RedirectSlashes, middleware.RedirectSlashes,
middleware.Recoverer, middleware.Recoverer,
cors.Handler,
) )
router.Route("/v1", func(r chi.Router) { router.Route("/v1", func(r chi.Router) {