adding endpoint /all.js

This commit is contained in:
stephanie 2022-01-04 06:53:48 -08:00 committed by George Shammas
parent cb6219d000
commit a5adaf7e50
1 changed files with 8 additions and 2 deletions

View File

@ -7,7 +7,7 @@ import (
"strconv"
"strings"
"time"
"encoding/json"
"github.com/gin-gonic/gin"
proxyproto "github.com/pires/go-proxyproto"
)
@ -130,6 +130,7 @@ func mainHandler(c *gin.Context) {
}
wantsJSON := len(fields) >= 2 && fields[1] == "json"
wantsJS := len(fields) >= 2 && fields[1] == "js"
switch fields[0] {
case "":
@ -147,6 +148,10 @@ func mainHandler(c *gin.Context) {
case "all":
if wantsJSON {
c.JSON(200, c.Keys)
} else if wantsJS {
c.Writer.Header().Set("Content-Type", "application/javascript")
response, _ := json.Marshal(c.Keys)
c.String(200, "ifconfig_io = %v\n", string(response))
} else {
c.String(200, "%v", c.Keys)
}
@ -190,6 +195,7 @@ func main() {
r.GET(fmt.Sprintf("/%s", route), mainHandler)
r.GET(fmt.Sprintf("/%s.json", route), mainHandler)
}
r.GET("/all.js", mainHandler)
r.GET("/", mainHandler)
errc := make(chan error)