it all works

This commit is contained in:
Tommy Parnell
2022-02-04 12:30:42 -05:00
parent aa33ed1324
commit 5e06d42b1f

11
main.go
View File

@@ -10,15 +10,20 @@ import (
) )
func main() { func main() {
token := os.Getenv("API_TOKEN")
if token == "" {
token = "ckynqopsk0002zp6ehp2n6d5n"
}
app := fiber.New() app := fiber.New()
app.Use(logger.New(logger.Config{ app.Use(logger.New(logger.Config{
// log query string parameters // log query string parameters
Format: "[${ip}]:${port} ${status} - ${method} ${path} - ${queryParams}\n", Format: "[${ip}]:${port} ${status} - ${method} ${path} - ${queryParams}\n",
})) }))
app.Use(func(c *fiber.Ctx) error { app.Use(func(c *fiber.Ctx) error {
token := os.Getenv("API_TOKEN") authHeader := c.Get("Authorization")
if token == "" { if authHeader != "Bearer "+token {
token = "ckynqopsk0002zp6ehp2n6d5n" c.Status(401).SendString("Unauthorized")
return nil
} }
return c.Next() return c.Next()
}) })