mirror of
https://github.com/ProjectSegfault/publapi.git
synced 2024-09-08 04:45:33 +05:30
41 lines
830 B
Go
41 lines
830 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/ProjectSegfault/publapi/pages"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// publapi is a simple API for Project Segfault's public shared server (pubnix).
|
|
func main() {
|
|
app := fiber.New(fiber.Config{
|
|
AppName: "publapi",
|
|
EnableTrustedProxyCheck: true,
|
|
TrustedProxies: []string{"0.0.0.0/0"},
|
|
ProxyHeader: fiber.HeaderXForwardedFor,
|
|
})
|
|
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
return c.JSON(fiber.Map{
|
|
"message": "welcome to publapi",
|
|
"status": c.Response().StatusCode(),
|
|
})
|
|
})
|
|
|
|
app.Get("/users", pages.UsersPage)
|
|
|
|
app.Post("/signup", pages.SignupPage)
|
|
|
|
app.Listen(GetPort())
|
|
}
|
|
|
|
// GetPort returns the port to listen on
|
|
func GetPort() string {
|
|
port := os.Getenv("PUBLAPI_PORT")
|
|
if port == "" {
|
|
port = "3000"
|
|
}
|
|
return ":" + port
|
|
}
|