

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Learn HTTP Servers
incomplete
2: Goroutines in Servers
incomplete
3: Project Setup
incomplete
4: Server
incomplete
5: Fileservers
incomplete
6: Fileserver Quiz
incomplete
7: Serving Images
incomplete
8: Workflow Tips
incomplete
9: Custom Handlers
incomplete
10: Handler Review
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
You may be wondering how the fileserver knew to serve the index.html file to the root of the server. It's such a common convention on the web to use a file called index.html to serve the webpage for a given path, that the Go standard library's FileServer does it automatically.
When using a standard fileserver, the path to a file on disk is the same as its URL path. An exception is that index.html is served from / instead of /index.html.
Run your chirpy server again, and open http://localhost:8080/index.html in a new browser tab. You'll notice that you're redirected to http://localhost:8080/.
This works for all directories, not just the root!
For example:
/index.html will be served from //pages/index.html will be served from /pages/pages/about/index.html will be served from /pages/aboutAlternatively, try opening a URL that doesn't exist, like http://localhost:8080/doesntexist.html. You'll see that the fileserver returns a 404 error.
Let's serve another type of file from our server: an image. Chirpy has a slick logo, and we need to serve it so that our users can load it in their browsers and mobile apps.
Download the Chirpy logo from below and add it to your project directory.
Configure its filepath so that it's accessible from this URL:
http://localhost:8080/assets/logo.png
Run and submit the CLI tests.