Skip to content

Commit

Permalink
馃悶 fix: ghost fatal error from 404 route
Browse files Browse the repository at this point in the history
  • Loading branch information
shurco committed Jul 28, 2023
1 parent 3cb5418 commit 70a7c8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 16 additions & 5 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"fmt"
"net"
"net/http"
"os"
"strings"

"github.com/armon/go-proxyproto"
"github.com/rs/zerolog"

"github.com/gofiber/contrib/fiberzerolog"
"github.com/gofiber/fiber/v2"
Expand All @@ -18,6 +16,7 @@ import (
"github.com/shurco/litecart/internal/queries"
"github.com/shurco/litecart/internal/routes"
"github.com/shurco/litecart/pkg/fsutil"
"github.com/shurco/litecart/pkg/logging"
)

//go:embed migrations/*.sql
Expand All @@ -31,7 +30,7 @@ var (
// NewApp is ...
func NewApp() error {
DevMode = true
log := zerolog.New(os.Stderr).With().Timestamp().Logger()
log := logging.Log()

if err := fsutil.MkDirs(0775, "./uploads"); err != nil {
log.Err(err).Send()
Expand Down Expand Up @@ -72,10 +71,8 @@ func NewApp() error {

routes.SiteRoutes(app)
routes.AdminRoutes(app)

routes.ApiPrivateRoutes(app)
routes.ApiPublicRoutes(app)

routes.NotFoundRoute(app)

ln, err := net.Listen("tcp", fmt.Sprintf(":%d", 8080))
Expand All @@ -90,6 +87,7 @@ func NewApp() error {
return nil
}

/*
func DatabaseCheck(c *fiber.Ctx) error {
db := queries.DB()
if !db.IsInstalled() {
Expand All @@ -101,6 +99,19 @@ func DatabaseCheck(c *fiber.Ctx) error {
}
return c.Next()
}
*/

func DatabaseCheck(c *fiber.Ctx) error {
db := queries.DB()
if !db.IsInstalled() {
if !strings.HasPrefix(c.Path(), "/_/install") && !strings.HasPrefix(c.Path(), "/api") {
return c.Redirect("/_/install")
}
} else if strings.HasPrefix(c.Path(), "/_/install") {
return c.Redirect("/_")
}
return c.Next()
}

func SubdomainCheck(c *fiber.Ctx) error {
db := queries.DB()
Expand Down
3 changes: 1 addition & 2 deletions internal/routes/not_found_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
// NotFoundRoute func for describe 404 Error route.
func NotFoundRoute(a *fiber.App) {
a.Use(func(c *fiber.Ctx) error {
path := strings.Split(c.Path(), "/")[1]
if path == "api" {
if strings.HasPrefix(c.Path(), "/api") {
return webutil.Response(c, fiber.StatusNotFound, "Not Found", nil)
}
return c.Status(fiber.StatusNotFound).Render("error/404", fiber.Map{}, "site/layouts/clear")
Expand Down

0 comments on commit 70a7c8b

Please sign in to comment.