Skip to content

Commit

Permalink
opend cors headers
Browse files Browse the repository at this point in the history
  • Loading branch information
tawalaya committed Apr 2, 2019
1 parent b779f60 commit 6317403
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM golang:1.12
WORKDIR /opt/dal
FROM golang:1.12 as build
WORKDIR /opt/vdc
COPY . .
RUN CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-w -s -X main.Build=$(git rev-parse --short HEAD)" -o mock-vdc

FROM alpine
COPY --from=build /opt/vdc/mock-vdc /opt/vdc/mock-vdc
EXPOSE 8080
ENTRYPOINT [ "/opt/dal/mock-vdc" ,"--port","8080"]
ENTRYPOINT [ "/opt/vdc/mock-vdc" ,"--port","8080"]
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (v *VDCServer) Router() *mux.Router {
r := mux.NewRouter()

r.Methods("GET").Path("/ask").Handler(http.HandlerFunc(v.ask))
r.Methods("OPTIONS").Path("/ask").Handler(http.HandlerFunc(v.ask))
r.NotFoundHandler = http.HandlerFunc(v.notFound)
return r
}
Expand Down Expand Up @@ -214,7 +215,7 @@ func (v *VDCServer) notFound(w http.ResponseWriter, r *http.Request) {
func (v *VDCServer) ask(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, X-DITAS-CALLBACK")
w.Header().Set("Access-Control-Allow-Headers", "*")

v.Log(fmt.Sprintf("[%s] %s", r.Method, r.RequestURI))
v.Trace(r, "vdc-request")
Expand Down

0 comments on commit 6317403

Please sign in to comment.