You've already forked top-wallpaper
46 lines
936 B
Go
46 lines
936 B
Go
package main
|
|
|
|
import (
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/echo/v4/middleware"
|
|
"github.com/labstack/gommon/log"
|
|
tphttp "github.com/siteworxpro/top-wallpaper/http"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
|
|
e := echo.New()
|
|
e.Logger.SetLevel(log.INFO)
|
|
|
|
e.HideBanner = true
|
|
|
|
e.Use(tphttp.GetCustomContext)
|
|
e.Use(middleware.Logger())
|
|
e.Use(middleware.RequestID())
|
|
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
|
AllowOrigins: strings.Split(os.Getenv("ALLOWED_ORIGINS"), ","),
|
|
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
|
|
AllowMethods: []string{http.MethodGet, http.MethodOptions},
|
|
}))
|
|
|
|
path := os.Getenv("PATH_PREFIX")
|
|
if path == "" {
|
|
path = "/"
|
|
}
|
|
|
|
e.GET(path, tphttp.Get)
|
|
|
|
e.Logger.Info("Starting server at path " + path)
|
|
// start the server
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
e.Logger.Fatal(e.Start(":" + port))
|
|
}
|