Skip to content
This repository was archived by the owner on Aug 24, 2020. It is now read-only.

Commit

Permalink
proxy de imagem para suportar imagem em canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonata-menezes committed Jun 4, 2018
1 parent f0a164d commit fb00f54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"io/ioutil"
"encoding/json"
"github.com/parnurzeal/gorequest"
)

type DefaultMessage struct {
Expand Down Expand Up @@ -284,6 +285,22 @@ func PostSalvarTime(response http.ResponseWriter, request *http.Request) {
}


func Proxy(response http.ResponseWriter, request *http.Request) {
url := request.URL.Query().Get("url")
if url == "" {
response.WriteHeader(http.StatusNoContent)
return
}
responseProxy, by, errs := gorequest.New().Get(url).EndBytes()
if len(errs) > 0 {
response.WriteHeader(http.StatusNoContent)
return
}
response.Header().Set("content-type", responseProxy.Header.Get("content-type"))
response.Write(by)
response.WriteHeader(responseProxy.StatusCode)
}


func responseDefault(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "*")
Expand Down
2 changes: 2 additions & 0 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ func BuildRoutes(mux *chi.Mux){
mux.Post("/login/cartolafc", PostLogin)
mux.Get("/time/info", GetMeuTime)
mux.Post("/time/salvar", PostSalvarTime)

mux.Get("/proxy", Proxy)
}

0 comments on commit fb00f54

Please sign in to comment.