Skip to content

Commit

Permalink
remove web routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sayem314 committed Sep 29, 2024
1 parent b3720a5 commit ef3637d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 104 deletions.
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/go-playground/validator/v10 v10.22.1
github.com/gofiber/fiber/v2 v2.52.5
github.com/gofiber/swagger v1.1.0
github.com/gofiber/template/handlebars/v2 v2.1.10
github.com/knadh/koanf/parsers/yaml v0.1.0
github.com/knadh/koanf/providers/confmap v0.1.0
github.com/knadh/koanf/providers/env v1.0.0
Expand Down Expand Up @@ -40,8 +39,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
Expand All @@ -54,7 +51,6 @@ require (
github.com/klauspost/compress v1.17.10 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -67,7 +63,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/swaggo/files/v2 v2.0.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.56.0 // indirect
Expand Down
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yG
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofiber/swagger v1.1.0 h1:ff3rg1fB+Rp5JN/N8jfxTiZtMKe/9tB9QDc79fPiJKQ=
github.com/gofiber/swagger v1.1.0/go.mod h1:pRZL0Np35sd+lTODTE5The0G+TMHfNY+oC4hM2/i5m8=
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
github.com/gofiber/template/handlebars/v2 v2.1.10 h1:Qc+uUMULCqW60LF4VKO1REpiyDAUy3vqW7xq66FPJGM=
github.com/gofiber/template/handlebars/v2 v2.1.10/go.mod h1:84WH9st5OJi255EGjuMAOqUVQ+Q2jUNhUKYbS5DgAcI=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
Expand Down Expand Up @@ -90,8 +84,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mailgun/raymond/v2 v2.0.48 h1:5dmlB680ZkFG2RN/0lvTAghrSxIESeu9/2aeDqACtjw=
github.com/mailgun/raymond/v2 v2.0.48/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNfj4KA0W54Z18=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down Expand Up @@ -126,11 +118,7 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -156,8 +144,6 @@ golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -170,8 +156,6 @@ golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
12 changes: 4 additions & 8 deletions internal/handlers/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package handlers

import "github.com/gofiber/fiber/v2"

type ResponseHello struct {
Hello string `json:"hello"`
}

// @Summary Hello
// @Description Hello
// @Tags root
Expand All @@ -14,11 +18,3 @@ func RootHandlerHello(c *fiber.Ctx) error {
Hello: "world",
})
}

func RootHandlerWeb(c *fiber.Ctx) error {
return c.Redirect("/app")
}

type ResponseHello struct {
Hello string `json:"hello"`
}
88 changes: 13 additions & 75 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/handlebars/v2"
"github.com/rs/zerolog/log"

"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/lunarr-app/lunarr-go/internal/handlers"
"github.com/lunarr-app/lunarr-go/internal/handlers/auth"
"github.com/lunarr-app/lunarr-go/internal/handlers/movies"
"github.com/lunarr-app/lunarr-go/internal/handlers/users"
"github.com/lunarr-app/lunarr-go/internal/server/middleware"
"github.com/lunarr-app/lunarr-go/internal/tmdb"
"github.com/lunarr-app/lunarr-go/web"
"github.com/lunarr-app/lunarr-go/web/router"

"github.com/gofiber/swagger"
_ "github.com/lunarr-app/lunarr-go/docs"
Expand All @@ -36,91 +29,36 @@ import (
// @in query
// @name api_key
func New() *fiber.App {
// Define custom template functions
templateFuncs := map[string]interface{}{
"TMDbGetImageURL": tmdb.GetImageURL,
"TMDbFormatReleaseDate": tmdb.FormatReleaseDate,
"IncludeFile": web.IncludeFile,
}
app := fiber.New()

// Load views using embed FS
views, err := web.GetViewsFS()
if err != nil {
log.Fatal().Err(err).Msg("Failed to load web views")
}

// Create the handlebars engine with the views file systemand template functions
engine := handlebars.NewFileSystem(views, ".hbs")
engine.AddFuncMap(templateFuncs)

// Create a new Fiber application
app := fiber.New(fiber.Config{
Views: engine,
})

// Set up a custom logger
customLogger := logger.New(logger.Config{
app.Use(logger.New(logger.Config{
Format: "${status} ${ip} ${method} ${path} - ${latency}\n",
TimeFormat: "2006-01-02 15:04:05",
})

// Register the custom logger as middleware
app.Use(customLogger)
}))

// Enable CORS with default options
app.Use(cors.New())
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowCredentials: false,
}))

// Swagger UI
app.Get("/swagger/*", swagger.HandlerDefault)

// Load assets using embed FS
assets, err := web.GetAssetsFS()
if err != nil {
log.Fatal().Err(err).Msg("Failed to load web assets")
}

// Serve static files
app.Use("/assets", filesystem.New(filesystem.Config{
Root: assets,
}))

// Register test route
// Register root routes
app.Get("/hello", handlers.RootHandlerHello)

// Register web routes
app.Get("/", handlers.RootHandlerWeb)
app.Get("/login", router.LoginPage)
app.Get("/signup", router.SignupPage)

// Create a sub-router for authenticated web routes
fe := app.Group("/app")

// Web routes to render error pages
fe.Get("/", router.RootRedirect) // This will be updated later when all features will be available
fe.Use(router.NotFoundPage)
fe.Use(router.InternalServerErrorPage)

// Register authenticated web routes
fe.Get("/movies", router.MoviePage)
fe.Get("/movies/:tmdb_id", router.MovieDetailsPage)

// Create a sub-router for auth
ha := app.Group("/auth")
ha.Post("/signup", auth.SignupHandler)
ha.Post("/login", auth.LoginHandler)

// Create a sub-router for authenticated API routes
api := app.Group("/api")
api.Use(middleware.AuthenticateAPI)

// Register authenticated API routes
// Register user routes
api.Get("/users", middleware.OnlyAdmin, users.UserRootHandler)
api.Get("/users/me", users.GetMeHandler)

// Register movie routes
api.Get("/movies", movies.MovieRootHandler)
api.Get("/movies/:tmdb_id", movies.MovieByIDHandler)
api.Get("/movies/:tmdb_id/stream", movies.MovieStreamHandler)

api.Get("/users", middleware.OnlyAdmin, users.UserRootHandler)
api.Get("/users/me", users.GetMeHandler)

// Return the application instance
return app
}

0 comments on commit ef3637d

Please sign in to comment.