43 lines
932 B
Go
43 lines
932 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"leech/config"
|
|
"leech/route"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
|
)
|
|
|
|
//go:embed assets/**
|
|
var assetsEmbed embed.FS
|
|
|
|
func main() {
|
|
config.Init()
|
|
app := fiber.New()
|
|
app.Use(logger.New(logger.Config{
|
|
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
|
|
}))
|
|
|
|
app.Use("/assets", filesystem.New(filesystem.Config{
|
|
Root: http.FS(assetsEmbed),
|
|
PathPrefix: "assets",
|
|
Browse: true,
|
|
}))
|
|
|
|
for dirName, dirToServe := range config.Config.ServeDirs {
|
|
fmt.Println("Registering route /serve/" + url.QueryEscape(dirName))
|
|
app.Static("/serve/"+url.QueryEscape(dirName), dirToServe) // For some reason this doesn't work and this is not my fault.
|
|
}
|
|
|
|
app.Use("/thumb", route.HandleThumb)
|
|
|
|
app.Use("/", route.HandleList)
|
|
|
|
app.Listen(config.Config.Host)
|
|
}
|