Skip to content

Add a simple frontend - #4

Open
FlaviaBastos wants to merge 1 commit into
douglasmakey:masterfrom
FlaviaBastos:add_frontend
Open

Add a simple frontend#4
FlaviaBastos wants to merge 1 commit into
douglasmakey:masterfrom
FlaviaBastos:add_frontend

Conversation

@FlaviaBastos

Copy link
Copy Markdown

Adds a simple frontend for the URL shortener

Comment thread handler/handler.go
if err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("URL Not Found"))
data, err := ioutil.ReadFile("frontend/index.html")

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread frontend/index.html
const inputField = document.querySelector('.urltochange');
const shortenButton = document.querySelector('.button');
const requestURL = "/encode/"
const xhr = new XMLHttpRequest();

Copy link
Copy Markdown

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
Copy Markdown
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