2022-01-17 20:23:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-01-17 22:34:05 +00:00
|
|
|
"codeberg.org/video-prize-ranch/rimgo/pages"
|
|
|
|
"codeberg.org/video-prize-ranch/rimgo/static"
|
2022-04-22 15:55:53 +00:00
|
|
|
"codeberg.org/video-prize-ranch/rimgo/utils"
|
2022-01-17 22:34:05 +00:00
|
|
|
"codeberg.org/video-prize-ranch/rimgo/views"
|
2022-01-17 20:23:04 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
2022-04-22 15:38:09 +00:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/recover"
|
2022-01-17 20:23:04 +00:00
|
|
|
"github.com/gofiber/template/handlebars"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-04-22 15:55:53 +00:00
|
|
|
utils.LoadConfig()
|
2022-01-17 22:34:05 +00:00
|
|
|
|
2022-01-17 20:23:04 +00:00
|
|
|
engine := handlebars.NewFileSystem(http.FS(views.GetFiles()), ".hbs")
|
|
|
|
app := fiber.New(fiber.Config{
|
2022-01-17 22:34:05 +00:00
|
|
|
Views: engine,
|
2022-04-22 15:55:53 +00:00
|
|
|
Prefork: utils.Config["fiberPrefork"].(bool),
|
2022-01-17 22:34:05 +00:00
|
|
|
UnescapePath: true,
|
2022-01-17 20:23:04 +00:00
|
|
|
StreamRequestBody: true,
|
|
|
|
})
|
|
|
|
|
2022-04-22 15:38:09 +00:00
|
|
|
app.Use(recover.New())
|
2022-01-17 20:23:04 +00:00
|
|
|
app.Use("/static", filesystem.New(filesystem.Config{
|
|
|
|
Root: http.FS(static.GetFiles()),
|
|
|
|
}))
|
|
|
|
|
2022-01-21 23:35:12 +00:00
|
|
|
app.Get("/robots.txt", func(c *fiber.Ctx) error {
|
|
|
|
file, _ := static.GetFiles().ReadFile("robots.txt")
|
|
|
|
_, err := c.Write(file)
|
|
|
|
return err
|
|
|
|
})
|
2022-04-10 15:24:54 +00:00
|
|
|
app.Get("/favicon.ico", func(c *fiber.Ctx) error {
|
|
|
|
file, _ := static.GetFiles().ReadFile("favicon/favicon.ico")
|
|
|
|
_, err := c.Write(file)
|
|
|
|
return err
|
|
|
|
})
|
2022-01-21 23:35:12 +00:00
|
|
|
|
2022-02-23 00:06:39 +00:00
|
|
|
app.Get("/", pages.HandleFrontpage)
|
|
|
|
app.Get("/:postID.gifv", pages.HandleEmbed)
|
2022-01-17 22:11:33 +00:00
|
|
|
app.Get("/:baseName.:extension", pages.HandleMedia)
|
2022-02-17 21:07:15 +00:00
|
|
|
app.Get("/:postID", pages.HandlePost)
|
2022-01-20 21:09:57 +00:00
|
|
|
app.Get("/a/:galleryID", pages.HandleGallery)
|
2022-02-18 21:56:56 +00:00
|
|
|
app.Get("/t/:tag", pages.HandleTag)
|
2022-01-28 01:41:10 +00:00
|
|
|
app.Get("/user/:userID", pages.HandleUser)
|
2022-02-17 21:07:15 +00:00
|
|
|
app.Get("/r/:sub/:postID", pages.HandlePost)
|
2022-01-28 01:41:10 +00:00
|
|
|
app.Get("/user/:userID/cover", pages.HandleUserCover)
|
|
|
|
app.Get("/user/:userID/avatar", pages.HandleUserAvatar)
|
2022-01-18 21:45:57 +00:00
|
|
|
app.Get("/gallery/:galleryID", pages.HandleGallery)
|
2022-01-17 20:23:04 +00:00
|
|
|
|
2022-04-22 15:55:53 +00:00
|
|
|
app.Listen(":" + utils.Config["port"].(string))
|
2022-01-17 22:34:05 +00:00
|
|
|
}
|