it all works
This commit is contained in:
11
main.go
11
main.go
@@ -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()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user