2022-05-18 22:54:07 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2022-05-20 01:59:53 +03:00
|
|
|
"github.com/JustKato/FreePad/lib/controllers"
|
2022-05-19 00:40:34 +03:00
|
|
|
"github.com/JustKato/FreePad/lib/routes"
|
2022-05-18 22:54:07 +03:00
|
|
|
"github.com/gin-gonic/gin"
|
2022-05-20 00:46:14 +03:00
|
|
|
"github.com/joho/godotenv"
|
2022-05-18 22:54:07 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-05-20 00:46:14 +03:00
|
|
|
|
|
|
|
// Load environment variables, ignore if any errors come up
|
2022-05-21 14:34:46 +03:00
|
|
|
_ = godotenv.Load()
|
2022-05-20 00:46:14 +03:00
|
|
|
|
2022-05-20 01:40:21 +03:00
|
|
|
dm, isDevelopment := os.LookupEnv("DEV_MODE")
|
|
|
|
if !isDevelopment && dm == "0" {
|
2022-05-18 22:54:07 +03:00
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
}
|
|
|
|
|
2022-05-19 01:55:14 +03:00
|
|
|
// Run the TaskManager
|
2022-05-20 01:59:53 +03:00
|
|
|
go controllers.TaskManager()
|
2022-05-19 01:55:14 +03:00
|
|
|
|
2022-05-18 22:54:07 +03:00
|
|
|
// Initialize the router
|
|
|
|
router := gin.Default()
|
|
|
|
|
2022-05-22 20:15:11 +03:00
|
|
|
// Apply the FreePad Headers
|
|
|
|
controllers.ApplyHeaders(router)
|
|
|
|
|
2022-05-19 00:31:13 +03:00
|
|
|
// Read HTML Templates
|
|
|
|
router.LoadHTMLGlob("templates/**/*.html")
|
|
|
|
|
|
|
|
// Load in static path
|
|
|
|
router.Static("/static", "static/")
|
|
|
|
|
2022-05-22 19:38:12 +03:00
|
|
|
// Implement the rate limiter
|
|
|
|
controllers.DoRateLimit(router)
|
|
|
|
|
2022-05-19 00:40:34 +03:00
|
|
|
// Add Routes
|
|
|
|
routes.HomeRoutes(router)
|
|
|
|
|
2022-05-18 22:54:07 +03:00
|
|
|
router.Run(":8080")
|
|
|
|
|
|
|
|
}
|