Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit 517ecc7

Browse files
committed
fix #21: support cors
1 parent 0537962 commit 517ecc7

File tree

9 files changed

+506
-2
lines changed

9 files changed

+506
-2
lines changed

api/http-client/rpc.v1.cors.http

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OPTIONS {{host}}/twirp/octolab.api.tablo.v1.TabloService/Get
2+
Origin: http://127.0.0.1
3+
4+
###

cmd/server/main.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"log"
55
"net/http"
66

7+
"github.com/go-chi/cors"
8+
79
v1 "go.octolab.org/ecosystem/tablo/internal/generated/api/v1"
810
server "go.octolab.org/ecosystem/tablo/internal/server/v1"
911
)
@@ -17,10 +19,18 @@ var (
1719
func main() {
1820
log.Printf("{commit: %q, date: %q, version: %q, port: 8080}\n", commit, date, version)
1921

20-
main := v1.NewTabloServiceServer(server.Tablo(), nil)
22+
handler := v1.NewTabloServiceServer(server.Tablo(), nil)
23+
middleware := cors.New(cors.Options{
24+
AllowedOrigins: []string{"*"},
25+
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
26+
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
27+
ExposedHeaders: []string{"Link"},
28+
AllowCredentials: true,
29+
MaxAge: 300,
30+
})
2131

2232
mux := http.NewServeMux()
23-
mux.Handle(main.PathPrefix(), main)
33+
mux.Handle(handler.PathPrefix(), middleware.Handler(handler))
2434

2535
log.Fatal(http.ListenAndServe(":8080", mux))
2636
}

env/docker/compose/docker-compose.base.yml

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ version: "3"
22

33
services:
44

5+
# cache:
6+
# image: octopot/tablo:cache
7+
# build:
8+
# context: ../cache
9+
# env_file:
10+
# - ../cache/.env
11+
#
12+
# monitoring:
13+
# image: octopot/tablo:monitoring
14+
# build:
15+
# context: ../monitoring
16+
# env_file:
17+
# - ../monitoring/.env
18+
519
service:
620
image: octopot/tablo:latest
721
build:

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.11
55
require (
66
github.com/Masterminds/squirrel v1.1.0
77
github.com/adlio/trello v1.4.0
8+
github.com/go-chi/cors v1.0.0
89
github.com/go-sql-driver/mysql v1.4.1 // indirect
910
github.com/golang/protobuf v1.3.2
1011
github.com/google/go-github/v28 v28.1.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
66
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
77
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
88
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/go-chi/cors v1.0.0 h1:e6x8k7uWbUwYs+aXDoiUzeQFT6l0cygBYyNhD7/1Tg0=
10+
github.com/go-chi/cors v1.0.0/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I=
911
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
1012
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
1113
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=

vendor/github.com/go-chi/cors/README.md

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)