mirror of
https://github.com/pikami/cosmium.git
synced 2025-04-22 09:33:17 +01:00
Added support for using cosmosdb-explorer
This commit is contained in:
parent
b780e8c228
commit
31eaf0ad3f
@ -1,7 +1,28 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
var Config = ServerConfig{
|
import (
|
||||||
DatabaseAccount: "localhost",
|
"flag"
|
||||||
DatabaseDomain: "localhost",
|
"fmt"
|
||||||
DatabaseEndpoint: "https://localhost:8081/",
|
)
|
||||||
|
|
||||||
|
var Config = ServerConfig{}
|
||||||
|
|
||||||
|
func ParseFlags() {
|
||||||
|
host := flag.String("Host", "localhost", "Hostname")
|
||||||
|
port := flag.Int("Port", 8081, "Listen port")
|
||||||
|
explorerPath := flag.String("ExplorerDir", "/home/pk/pro/cosmos-explorer/dist", "Path to cosmos-explorer files")
|
||||||
|
tlsCertificatePath := flag.String("Cert", "../example.crt", "Hostname")
|
||||||
|
tlsCertificateKey := flag.String("CertKey", "../example.key", "Hostname")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
Config.Host = *host
|
||||||
|
Config.Port = *port
|
||||||
|
Config.ExplorerPath = *explorerPath
|
||||||
|
Config.TLS_CertificatePath = *tlsCertificatePath
|
||||||
|
Config.TLS_CertificateKey = *tlsCertificateKey
|
||||||
|
|
||||||
|
Config.DatabaseAccount = Config.Host
|
||||||
|
Config.DatabaseDomain = Config.Host
|
||||||
|
Config.DatabaseEndpoint = fmt.Sprintf("https://%s:%d/", Config.Host, Config.Port)
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,10 @@ type ServerConfig struct {
|
|||||||
DatabaseAccount string
|
DatabaseAccount string
|
||||||
DatabaseDomain string
|
DatabaseDomain string
|
||||||
DatabaseEndpoint string
|
DatabaseEndpoint string
|
||||||
|
|
||||||
|
ExplorerPath string
|
||||||
|
Port int
|
||||||
|
Host string
|
||||||
|
TLS_CertificatePath string
|
||||||
|
TLS_CertificateKey string
|
||||||
}
|
}
|
||||||
|
29
api/handlers/explorer.go
Normal file
29
api/handlers/explorer.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/pikami/cosmium/api/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterExplorerHandlers(router *gin.Engine) {
|
||||||
|
explorer := router.Group("/_explorer")
|
||||||
|
{
|
||||||
|
explorer.Use(func(ctx *gin.Context) {
|
||||||
|
if ctx.Param("filepath") == "/config.json" {
|
||||||
|
endpoint := fmt.Sprintf("https://%s:%d", config.Config.Host, config.Config.Port)
|
||||||
|
ctx.JSON(200, gin.H{
|
||||||
|
"BACKEND_ENDPOINT": endpoint,
|
||||||
|
"MONGO_BACKEND_ENDPOINT": endpoint,
|
||||||
|
"PROXY_PATH": "/",
|
||||||
|
"EMULATOR_ENDPOINT": endpoint,
|
||||||
|
})
|
||||||
|
ctx.Abort()
|
||||||
|
} else {
|
||||||
|
ctx.Next()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
explorer.Static("/", config.Config.ExplorerPath)
|
||||||
|
}
|
||||||
|
}
|
@ -35,5 +35,7 @@ func CreateRouter() *gin.Engine {
|
|||||||
router.GET("/offers", handlers.GetOffers)
|
router.GET("/offers", handlers.GetOffers)
|
||||||
router.GET("/", handlers.GetServerInfo)
|
router.GET("/", handlers.GetServerInfo)
|
||||||
|
|
||||||
|
handlers.RegisterExplorerHandlers(router)
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
8
main.go
8
main.go
@ -4,11 +4,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pikami/cosmium/api"
|
"github.com/pikami/cosmium/api"
|
||||||
|
"github.com/pikami/cosmium/api/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello world")
|
config.ParseFlags()
|
||||||
|
|
||||||
router := api.CreateRouter()
|
router := api.CreateRouter()
|
||||||
router.RunTLS(":8081", "../example.crt", "../example.key")
|
router.RunTLS(
|
||||||
|
fmt.Sprintf(":%d", config.Config.Port),
|
||||||
|
config.Config.TLS_CertificatePath,
|
||||||
|
config.Config.TLS_CertificateKey)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user