Skip to content

Static File Server - By using this package you can serve static files with 404 Error fallback to custom http.handler

License

Notifications You must be signed in to change notification settings

amirhosseinab/sfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Static File Server

By using this package you can serve static files with 404 Error fallback to custom http.handler.

For example if you want to serve static contents of a Single Page Application, you can always serve index.html when 404 error occurs.

Example:

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		log.Panic("$PORT should not be empty")
	}

	h := sfs.New(http.Dir("client/build"), IndexHandler)

	log.Fatal(http.ListenAndServe(":"+port, h))
}

func IndexHandler(w http.ResponseWriter, r *http.Request) {
	http.ServeFile(w, r, "client/build/index.html")
}

About

Static File Server - By using this package you can serve static files with 404 Error fallback to custom http.handler

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages