mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2026-10-21 01:34:22 +00:00
feat: set up embedded static server
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
1 parent
dea9f3cfaa
commit
9600c21c5a
18 files changed
+1838
-7
No files matched your search
+13
-4
@@ -3,25 +3,34 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/medium.rip/api/routes"
|
||||
"github.com/medium.rip/internal/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
"github.com/gofiber/template/html"
|
||||
)
|
||||
|
||||
func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup) {
|
||||
func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup, engine *html.Engine, fs http.FileSystem) {
|
||||
app := fiber.New(fiber.Config{
|
||||
StreamRequestBody: true,
|
||||
ServerHeader: "Katbox",
|
||||
AppName: "Katbox",
|
||||
DisableStartupMessage: true,
|
||||
Views: engine,
|
||||
})
|
||||
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.SendString("OK")
|
||||
})
|
||||
// static file server
|
||||
app.Use("/assets", filesystem.New(filesystem.Config{
|
||||
Root: fs,
|
||||
Browse: config.Conf.Env == "dev",
|
||||
}))
|
||||
|
||||
routes.RegisterRoutes(app)
|
||||
|
||||
go func(app *fiber.App) {
|
||||
log.Printf("Starting http server at: http://localhost:%s", config.Conf.Port)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package routes
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func show(c *fiber.Ctx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func index(c *fiber.Ctx) error {
|
||||
return c.Render("index", fiber.Map {
|
||||
"Title": "medium.rip",
|
||||
})
|
||||
}
|
||||
|
||||
func RegisterRoutes(app *fiber.App) {
|
||||
app.Get("/", index)
|
||||
app.Get("/:id", show)
|
||||
}
|
||||
Reference in new issue
Block a user