-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a simple frontend #4
base: master
Are you sure you want to change the base?
Conversation
@@ -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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use there http.ServeFile(). So you don't need to handle errors etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh! I didn't know about that... thanks for pointing that out. I will check this one also.
const inputField = document.querySelector('.urltochange'); | ||
const shortenButton = document.querySelector('.button'); | ||
const requestURL = "/encode/" | ||
const xhr = new XMLHttpRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You start there by using ECMA6, so why not using directly the new Fetch API which was introduced in ECMA6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxibanki Good point, thanks for bringing this up!
I'm fairly new to JS so I don't know all the tools yet. I will take a look and see how to make this change.
Adds a simple frontend for the URL shortener