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:

  1. app.Static(prefix, root string)

Use the following code to serve files in a directory named ./public:

  1. app := fiber.New()
  2.  
  3. app.Static("/", "./public")
  4.  
  5. app.Listen(8080)

Now, you can load the files that are in the ./public directory:

  1. http://localhost:8080/hello.html
  2. http://localhost:8080/js/jquery.js
  3. http://localhost:8080/css/style.css