diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97379df2..365c1726 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,3 +23,9 @@ docker run --rm -it -p 5984:5984 -v `pwd`/.couchdb/data:/opt/couchdb/data -v `pw - WebUI: - username: `testuser` - password: `testuser` + + +# Running tests + +- ng test --include='**/base_client.spec.ts' +- ng test --include='lib/**/*.spec.ts' diff --git a/README.md b/README.md index 9dc55377..2e961d9d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,4 @@ Find & replace the following - `fastenhealth` - find and replace this with your binary name - make sure you rename the folder as well. -# Running tests - -- ng test --include='**/base_client.spec.ts' + diff --git a/backend/pkg/web/handler/cors_proxy.go b/backend/pkg/web/handler/cors_proxy.go new file mode 100644 index 00000000..31fc2ea5 --- /dev/null +++ b/backend/pkg/web/handler/cors_proxy.go @@ -0,0 +1,52 @@ +package handler + +import ( + "fmt" + "github.com/gin-gonic/gin" + "log" + "net/http" + "net/http/httputil" + "net/url" + "strings" +) + +//TODO, there are security implications to this, we need to make sure we lock this down. +func CORSProxy(c *gin.Context) { + //appConfig := c.MustGet("CONFIG").(config.Interface) + corsUrl := fmt.Sprintf("https://%s", strings.TrimPrefix(c.Param("proxyPath"), "/")) + + remote, err := url.Parse(corsUrl) + remote.RawQuery = c.Request.URL.Query().Encode() + if err != nil { + panic(err) + } + + proxy := httputil.ReverseProxy{} + //Define the director func + //This is a good place to log, for example + proxy.Director = func(req *http.Request) { + req.Header = c.Request.Header + req.Header.Add("X-Forwarded-Host", req.Host) + req.Header.Add("X-Origin-Host", remote.Host) + req.Host = remote.Host + req.URL.Scheme = remote.Scheme + req.URL.Host = remote.Host + log.Printf(c.Param("proxyPath")) + req.URL.Path = remote.Path + + //TODO: throw an error if the remote.Host is not allowed + } + + proxy.ModifyResponse = func(r *http.Response) error { + //b, _ := ioutil.ReadAll(r.Body) + //buf := bytes.NewBufferString("Monkey") + //buf.Write(b) + //r.Body = ioutil.NopCloser(buf) + r.Header.Set("Access-Control-Allow-Methods", "GET,HEAD") + r.Header.Set("Access-Control-Allow-Credentials", "true") + r.Header.Set("Access-Control-Allow-Origin", "*") + return nil + } + + proxy.ServeHTTP(c.Writer, c.Request) +} diff --git a/backend/pkg/web/server.go b/backend/pkg/web/server.go index 7bc546bc..3a20f628 100644 --- a/backend/pkg/web/server.go +++ b/backend/pkg/web/server.go @@ -44,6 +44,8 @@ func (ae *AppEngine) Setup(logger *logrus.Entry) *gin.Engine { api.GET("/metadata/source", handler.GetMetadataSource) r.Any("/database/*proxyPath", handler.CouchDBProxy) + r.GET("/cors/*proxyPath", handler.CORSProxy) + r.OPTIONS("/cors/*proxyPath", handler.CORSProxy) } } diff --git a/frontend/src/app/models/queue/source-sync-message.ts b/frontend/src/app/models/queue/source-sync-message.ts index 4e22e512..6bde5b7f 100644 --- a/frontend/src/app/models/queue/source-sync-message.ts +++ b/frontend/src/app/models/queue/source-sync-message.ts @@ -4,4 +4,6 @@ export class SourceSyncMessage { source: Source userIdentifier: string encryptionKey?: string + + response?: any } diff --git a/frontend/src/app/pages/auth-signin/auth-signin.component.html b/frontend/src/app/pages/auth-signin/auth-signin.component.html index 3db5b09b..e4fa1e2e 100644 --- a/frontend/src/app/pages/auth-signin/auth-signin.component.html +++ b/frontend/src/app/pages/auth-signin/auth-signin.component.html @@ -7,18 +7,15 @@