Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 1.72 KB

README.md

File metadata and controls

73 lines (50 loc) · 1.72 KB
title File Server
keywords
file server
static files
description Serving static files.

File Server Example

Github StackBlitz

This project demonstrates how to set up a simple file server in a Go application using the Fiber framework.

Prerequisites

Ensure you have the following installed:

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/file-server
  2. Install dependencies:

    go get

Running the Application

  1. Start the application:

    go run main.go
  2. Open one of the files in the files directory:

    • http://localhost:3000/hello.txt
    • http://localhost:3000/gopher.gif

    Only the files in that directory are served, so http://localhost:3000/ itself answers 404 Not Found.

Example

Here is an example main.go file for the Fiber application serving static files:

package main

import (
    "log"

    "github.com/gofiber/fiber/v3"
    "github.com/gofiber/fiber/v3/middleware/static"
)

func main() {
    app := fiber.New()

    // Serve static files from the "files" directory
    app.Get("/*", static.New("./files"))

    log.Fatal(app.Listen(":3000"))
}

References