Giter Club home page Giter Club logo

Comments (6)

natefinch avatar natefinch commented on June 10, 2024

actually, this seems to happen for sub directories as well, which means I'm misunderstanding something.

	box := packr.NewBox("./public")

	http.Handle("/", http.FileServer(box))
	fmt.Println("serving docs at http://localhost:8080")
	fmt.Println("hit ctrl-C to cancel")
	go browser.OpenURL("http://localhost:8080")
	log.Fatal(http.ListenAndServe(":8080", nil))

^^ This will serve up what's in ./public if the folder exists, but if I remove the folder, it gives me 404s.

from packr.

natefinch avatar natefinch commented on June 10, 2024

note that this is after running packr, while having a packer file that looks like this:

func init() {
	packr.PackJSONBytes("./public", "index.html", "\"SGkgTWFyayE=\"")
	}

from packr.

markbates avatar markbates commented on June 10, 2024

Looks like the problem actually has to do with how http.FileServer handles index.html files:

http.Handle("/", http.FileServer(http.Dir("/tmp")))
As a special case, the returned file server redirects any request ending in "/index.html" to the same path, without the final "index.html".

If I throw any other file in the box it works just as expected. It's literally only index.html files.

from packr.

natefinch avatar natefinch commented on June 10, 2024

oh man, that is crazy town. Thanks for figuring this out :)

from packr.

markbates avatar markbates commented on June 10, 2024

lol. Tell me about it! I had to dig deep to figure how to make it work. They’re doing some really strange things in the http package.

from packr.

dmitshur avatar dmitshur commented on June 10, 2024

If you want an http.FileServer-like construct with ability to turn off special handling of index.html files, it's quite easy to make your own. You can see an example of one I've created at https://godoc.org/github.com/shurcooL/httpgzip#FileServer.

from packr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.