From a635513d66fd4d2c605a0e64b4fa94828c64610e Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sun, 10 May 2020 16:33:00 -0700 Subject: linked backend and frontend --- Makefile | 4 ++- backend/api/api.go | 4 +-- backend/api/routes.go | 8 ++++++ frontend/package.json | 1 + frontend/src/components/Inputs.js | 1 + frontend/src/components/PasteArea.js | 54 +++++++++++++++++++++++++++++++++--- 6 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a07153b..472fb7c 100644 --- a/Makefile +++ b/Makefile @@ -12,4 +12,6 @@ docker-push: fe-run: cd frontend && yarn start fe-build: - cd frontend && yarn build \ No newline at end of file + cd frontend && yarn build +all: + make -j 2 run fe-run \ No newline at end of file diff --git a/backend/api/api.go b/backend/api/api.go index c197774..59242ef 100644 --- a/backend/api/api.go +++ b/backend/api/api.go @@ -30,8 +30,8 @@ func Serve(port int) { // Define Mux Router r := mux.NewRouter() r.HandleFunc("/health", healthCheckFunc) - r.HandleFunc("/api", insertFunc).Methods("POST") - r.HandleFunc("/api/{hash}", getHashFunc).Methods("GET") + r.HandleFunc("/api", insertFunc).Methods("POST", "OPTIONS") + r.HandleFunc("/api/{hash}", getHashFunc).Methods("GET", "OPTIONS") http.Handle("/", r) diff --git a/backend/api/routes.go b/backend/api/routes.go index a65c886..07bea5a 100644 --- a/backend/api/routes.go +++ b/backend/api/routes.go @@ -18,6 +18,10 @@ func healthCheckFunc(w http.ResponseWriter, r *http.Request) { } func insertFunc(w http.ResponseWriter, r *http.Request) { + + // Allow CORS + w.Header().Set("Access-Control-Allow-Origin", "*") + // get content _ = r.ParseMultipartForm(0) expiry := r.FormValue("expiry") @@ -38,6 +42,10 @@ func insertFunc(w http.ResponseWriter, r *http.Request) { } func getHashFunc(w http.ResponseWriter, r *http.Request) { + + // Allow CORS + w.Header().Set("Access-Control-Allow-Origin", "*") + hash := mux.Vars(r)["hash"] paste, err := cache.C.Get(hash) diff --git a/frontend/package.json b/frontend/package.json index 26a63d5..d32e1cc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", + "axios": "^0.19.2", "d3-scale": "^3.2.1", "rc-slider": "^9.2.4", "react": "^16.13.1", diff --git a/frontend/src/components/Inputs.js b/frontend/src/components/Inputs.js index aa68a70..110d5bd 100644 --- a/frontend/src/components/Inputs.js +++ b/frontend/src/components/Inputs.js @@ -52,6 +52,7 @@ class PasteInput extends React.Component { placeholder="Paste your text here" value={this.props.content} id={this.props.id} + required onChange={this.props.onChange} className="lt-shadow" />