Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FlaviaBastos
Copy link

Adds a simple frontend for the URL shortener

@@ -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")

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.

Copy link
Author

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();

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?

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants