40 lines
708 B
Go
40 lines
708 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"github.com/gin-contrib/cors"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
Engine := gin.Default()
|
||
|
Engine.Use(cors.Default())
|
||
|
|
||
|
sapp := Engine.Group("/_app")
|
||
|
sapp.Static("/", "./static/_app")
|
||
|
|
||
|
static := Engine.Group("/static")
|
||
|
static.Static("/", "./static/static")
|
||
|
|
||
|
Engine.StaticFile("/", "./static/index.html")
|
||
|
Engine.StaticFile("/favicon.png", "./static/favicon.png")
|
||
|
|
||
|
Engine.ForwardedByClientIP = true
|
||
|
Engine.SetTrustedProxies([]string{"127.0.0.1"})
|
||
|
|
||
|
api := Engine.Group("/api")
|
||
|
|
||
|
api.GET("/sse", SSEHandler)
|
||
|
api.GET("/status", GetStatus)
|
||
|
api.POST("/status", SetStatus)
|
||
|
|
||
|
port := os.Getenv("PORT")
|
||
|
|
||
|
if port == "" {
|
||
|
port = "8080"
|
||
|
}
|
||
|
|
||
|
Engine.Run(":" + port)
|
||
|
}
|