Static files
To serve static files such as images, CSS and JavaScript files, replace your function handler with a file or directory string.
Function signature:
- app.Static(prefix, root string)
Use the following code to serve files in a directory named ./public
:
- app := fiber.New()
- app.Static("/", "./public")
- app.Listen(8080)
Now, you can load the files that are in the ./public
directory:
- http://localhost:8080/hello.html
- http://localhost:8080/js/jquery.js
- http://localhost:8080/css/style.css