Ryan Nguyen
Ryan Nguyen

Reputation: 15

GO - html file can't load external js file

I have a GO project which has UI written by html. In HTML file, I have written javascript, and I can install GO and load the UI successfully.

The problem is when I move those javascript code to an external file, and include it: . I only can build GO, but when load the UI, it has error 404 Not Found which is "myscripts.js" file. The weird thing is on its header of error: Remote Address:127.0.0.1:8080 Request URL:http://localhost:8080/subscribe/myscripts.js Request Method:GET Status Code:404 Not Found

Please help, I can't find any answer yet for this

Upvotes: 0

Views: 1290

Answers (1)

Elwinar
Elwinar

Reputation: 9519

That's normal if you only define handler for your endpoints.

You should add to your router the http.FileServer handler pointing to the directory that store your project files.

Additionally, think about the <base> that to define the root of your relative links, which will prevent errors such as path nesting.

Upvotes: 3

Related Questions