68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gin-contrib/cors"
|
|
"github.com/gin-gonic/gin"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var db *LDB
|
|
|
|
func main() {
|
|
db = connect()
|
|
defer db.db.Close()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
go startCleanupLoop(ctx, db.db, time.Hour, 24*time.Hour)
|
|
|
|
r := gin.Default()
|
|
gin.SetMode(gin.ReleaseMode)
|
|
//createSessionStore()
|
|
//r.Use(sessions.Sessions("luggageinfo_session", sessionStore))
|
|
createRateLimiters()
|
|
|
|
allowedOrigins := strings.Split(os.Getenv("CORS_ALLOWED_ORIGINS"), ",")
|
|
r.Use(cors.New(cors.Config{
|
|
AllowOrigins: allowedOrigins,
|
|
AllowMethods: []string{"GET", "POST"},
|
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
|
ExposeHeaders: []string{"Content-Length", "Authorization"},
|
|
AllowCredentials: true,
|
|
}))
|
|
|
|
r.Static("/static", "./static")
|
|
r.StaticFile("/favicon.ico", "./static/favicon.ico")
|
|
r.LoadHTMLGlob("./templates/*")
|
|
|
|
r.GET("/", htmlRL, webRoot)
|
|
//r.GET("/register", htmlRL, webRegister)
|
|
//r.GET("/register/success", htmlRL, webRegisterSuccess)
|
|
r.GET("/qr/:user", htmlRL, webQr)
|
|
r.GET("/ping", webPing)
|
|
|
|
api := r.Group("/api")
|
|
api.GET("/u/:user", jsonRL, webUserApi)
|
|
api.GET("/verify/:user", jsonRL, webVerifyUserApi)
|
|
api.GET("/checkname/:user", jsonRL, webCheckNameApi)
|
|
//api.POST("/register", jsonRL, webRegisterApi)
|
|
|
|
user := r.Group("/u")
|
|
user.GET("/:user", htmlRL, webUser)
|
|
user.GET("/:user/info", htmlRL, webUserInfo)
|
|
|
|
//auth := r.Group("/auth")
|
|
//auth.GET("/login", htmlRL, webLoginAuth)
|
|
//auth.POST("/login", htmlRL, webLoginAuthPost)
|
|
//auth.GET("/logout", htmlRL, webLogoutAuth)
|
|
|
|
err := r.Run()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|