Added CORS-Header in Go #8
2 changed files with 12 additions and 5 deletions
10
README.md
10
README.md
|
@ -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
|
||||||
|
@ -49,10 +49,10 @@ 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 |
|
||||||
|
|
||||||
## Channels
|
## Channels
|
||||||
|
|
||||||
|
|
7
main.go
7
main.go
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue