From 344a01eed67c6854f2147e89033bc370aa5fe2e1 Mon Sep 17 00:00:00 2001 From: FlaviaBastos Date: Fri, 20 Oct 2017 18:17:38 -0600 Subject: [PATCH] Add a simple frontend --- frontend/index.html | 117 ++++++++++++++++++++++++++++++++++++++++++++ handler/handler.go | 10 +++- 2 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 frontend/index.html diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..4c97eb9 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,117 @@ + + + + + url shortener + + + + + + + +
+
+ +
+ + +
+ + +
+
+
+ + + + diff --git a/handler/handler.go b/handler/handler.go index 449f1f4..e0fd96a 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -94,8 +94,14 @@ func (h handler) redirect(w http.ResponseWriter, r *http.Request) { model, err := h.storage.Load(code) if err != nil { - w.WriteHeader(http.StatusNotFound) - w.Write([]byte("URL Not Found")) + data, err := ioutil.ReadFile("frontend/index.html") + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte("Internal Server Error.")) + return + } + w.WriteHeader(http.StatusOK) + w.Write(data) return }