aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-10 16:33:00 -0700
committerjackyzha0 <[email protected]>2020-05-10 16:33:00 -0700
commita635513d66fd4d2c605a0e64b4fa94828c64610e (patch)
tree465b89c4028572ad9a213b746f50823fb28954a8 /backend
parentMerge pull request #11 from jackyzha0/pass_and_expiry (diff)
downloadctrl-v-a635513d66fd4d2c605a0e64b4fa94828c64610e.tar.xz
ctrl-v-a635513d66fd4d2c605a0e64b4fa94828c64610e.zip
linked backend and frontend
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api.go4
-rw-r--r--backend/api/routes.go8
2 files changed, 10 insertions, 2 deletions
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)