feat: add admin page

This commit is contained in:
2024-08-18 14:06:00 +07:00
parent fa52d8242e
commit 6a183f2c4e
2 changed files with 39 additions and 4 deletions

27
main.go
View File

@ -9,11 +9,13 @@ import (
"github.com/fossyy/filekeeper/middleware"
"github.com/fossyy/filekeeper/routes"
"github.com/fossyy/filekeeper/utils"
"net/http"
"strconv"
)
func main() {
serverAddr := fmt.Sprintf("%s:%s", utils.Getenv("SERVER_HOST"), utils.Getenv("SERVER_PORT"))
clientAddr := fmt.Sprintf("%s:%s", utils.Getenv("SERVER_HOST"), utils.Getenv("SERVER_PORT"))
adminAddr := fmt.Sprintf("%s:%s", utils.Getenv("SERVER_HOST"), "27000")
dbUser := utils.Getenv("DB_USERNAME")
dbPass := utils.Getenv("DB_PASSWORD")
@ -27,8 +29,27 @@ func main() {
smtpPort, _ := strconv.Atoi(utils.Getenv("SMTP_PORT"))
mailServer := email.NewSmtpServer(utils.Getenv("SMTP_HOST"), smtpPort, utils.Getenv("SMTP_USER"), utils.Getenv("SMTP_PASSWORD"))
app.Server = app.NewServer(serverAddr, middleware.Handler(routes.SetupRoutes()), *logger.Logger(), database, mailServer)
fmt.Printf("Listening on http://%s\n", app.Server.Addr)
app.Server = app.NewClientServer(clientAddr, middleware.Handler(routes.SetupRoutes()), *logger.Logger(), database, mailServer)
//TODO: Move admin route to its own folder
testRoute := http.NewServeMux()
testRoute.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, World!"))
return
})
app.Admin = app.NewAdminServer(adminAddr, testRoute, database)
go func() {
fmt.Printf("Admin Web App Listening on http://%s\n\n", app.Admin.Addr)
err := app.Admin.ListenAndServe()
if err != nil {
panic(err)
return
}
}()
fmt.Printf("Client Web App Listening on http://%s\n", app.Server.Addr)
err := app.Server.ListenAndServe()
if err != nil {
panic(err)