mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
boost
This commit is contained in:
parent
5a1a7608f1
commit
9f4af72c85
4 changed files with 36 additions and 28 deletions
34
internal/server/routes.go
Normal file
34
internal/server/routes.go
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
|
||||||
|
"github.com/rjNemo/rentease/constants"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Server) MountHandlers() {
|
||||||
|
// config
|
||||||
|
s.Router.HideBanner = true
|
||||||
|
s.Router.Debug = strings.ToLower(os.Getenv("DEBUG")) == "true"
|
||||||
|
s.Router.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
||||||
|
Format: "${time_rfc3339} [${method}: ${status}] ${uri}; ip=${remote_ip}; ${latency_human}; ${user_agent}\n",
|
||||||
|
}))
|
||||||
|
s.Router.HTTPErrorHandler = s.customHTTPErrorHandler
|
||||||
|
// middlewares
|
||||||
|
s.Router.Use(middleware.Recover())
|
||||||
|
s.Router.Use(middleware.Secure())
|
||||||
|
// static assets
|
||||||
|
s.Router.Static("/static", "assets")
|
||||||
|
// landing page
|
||||||
|
s.Router.GET("/", s.handleHomePage())
|
||||||
|
s.Router.GET(constants.RouteBooking, s.handleListBookingPage())
|
||||||
|
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
|
||||||
|
s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking())
|
||||||
|
s.Router.GET(fmt.Sprintf("%s/:id", constants.RouteBooking), s.handleBookingPage())
|
||||||
|
s.Router.POST(fmt.Sprintf("%s/:id/items", constants.RouteBooking), s.handleCreateItem())
|
||||||
|
s.Router.GET("/pdf", s.handleCreateInvoicePdf())
|
||||||
|
}
|
||||||
|
|
@ -7,15 +7,12 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"github.com/rjNemo/rentease/constants"
|
|
||||||
"github.com/rjNemo/rentease/internal/domains/booking"
|
"github.com/rjNemo/rentease/internal/domains/booking"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -35,29 +32,6 @@ func New(db *gorm.DB) *Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Server) MountHandlers() {
|
|
||||||
// config
|
|
||||||
s.Router.HideBanner = true
|
|
||||||
s.Router.Debug = strings.ToLower(os.Getenv("DEBUG")) == "true"
|
|
||||||
s.Router.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
|
||||||
Format: "${time_rfc3339} [${method}: ${status}] ${uri}; ip=${remote_ip}; ${latency_human}; ${user_agent}\n",
|
|
||||||
}))
|
|
||||||
s.Router.HTTPErrorHandler = s.customHTTPErrorHandler
|
|
||||||
// middlewares
|
|
||||||
s.Router.Use(middleware.Recover())
|
|
||||||
s.Router.Use(middleware.Secure())
|
|
||||||
// static assets
|
|
||||||
s.Router.Static("/static", "assets")
|
|
||||||
// landing page
|
|
||||||
s.Router.GET("/", s.handleHomePage())
|
|
||||||
s.Router.GET(constants.RouteBooking, s.handleListBookingPage())
|
|
||||||
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
|
|
||||||
s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking())
|
|
||||||
s.Router.GET(fmt.Sprintf("%s/:id", constants.RouteBooking), s.handleBookingPage())
|
|
||||||
s.Router.POST(fmt.Sprintf("%s/:id/items", constants.RouteBooking), s.handleCreateItem())
|
|
||||||
s.Router.GET("/pdf", s.handleCreateInvoicePdf())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s Server) Start() {
|
func (s Server) Start() {
|
||||||
go func() {
|
go func() {
|
||||||
if err := s.Router.Start(s.addr); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
if err := s.Router.Start(s.addr); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ templ BaseLayout() {
|
||||||
<link rel="stylesheet" href="/static/css/style.css"/>
|
<link rel="stylesheet" href="/static/css/style.css"/>
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body hx-boost="true">
|
||||||
<nav class="container-fluid">
|
<nav class="container-fluid">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/"><b>🏨 RentEase </b> </a></li>
|
<li><a href="/"><b>🏨 RentEase </b> </a></li>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func BaseLayout() templ.Component {
|
||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><title>RentEase | Your Property Management System</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"AI assistant to help you improve your management\"><link rel=\"icon\" href=\"/static/img/favicon.svg\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><link rel=\"stylesheet\" href=\"/static/css/style.css\"><script src=\"https://unpkg.com/htmx.org@1.9.10\"></script></head><body><nav class=\"container-fluid\"><ul><li><a href=\"/\"><b>🏨 RentEase </b></a></li></ul><ul><li><a href=\"/bookings\">Bookings</a></li><li><a href=\"/bookings/new\" role=\"button\">New Booking</a></li></ul></nav><main class=\"container\">")
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><title>RentEase | Your Property Management System</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"AI assistant to help you improve your management\"><link rel=\"icon\" href=\"/static/img/favicon.svg\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><link rel=\"stylesheet\" href=\"/static/css/style.css\"><script src=\"https://unpkg.com/htmx.org@1.9.10\"></script></head><body hx-boost=\"true\"><nav class=\"container-fluid\"><ul><li><a href=\"/\"><b>🏨 RentEase </b></a></li></ul><ul><li><a href=\"/bookings\">Bookings</a></li><li><a href=\"/bookings/new\" role=\"button\">New Booking</a></li></ul></nav><main class=\"container\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue