FAQ
Thanks Jesse,
That works great.
On Friday, July 26, 2013 5:30:38 AM UTC-4, Jesse McNelis wrote:

On Fri, Jul 26, 2013 at 6:45 PM, John-Alan Simmons <simmons....@gmail.com<javascript:>
wrote:
http.Handle("/public/", http.FileServer(http.Dir("../public")))
http.ListenAndServe(":8080", nil)

The problem is that when I go to localhost:8080/public/js/main.js, I just
get a "404 Not Found".

Since the two folders are at the same level, I can't quite figure out
what the code should be to access the contents of public?

http.FileServer() looks at the url to see what file to serve. But it
doesn't know which part is the file name and which part is the prefix from
the handler.
ie. when you request ''localhost:8080/public/js/main.js', http.FileServer()
looks for the file '/public/js/main.js' in the directory you gave it.
This ends up being '../public/public/js/main.js' which is obviously not
what you want.

You want.
http.Handle("/public/",
http.StripPrefix("/public/",http.FileServer(http.Dir("../public"))))

As given in the http.FileServer example.
http://golang.org/pkg/net/http/#FileServer

--
=====================
http://jessta.id.au
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 7 of 7 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 26, '13 at 8:45a
activeJul 26, '13 at 9:56a
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase