diff --git a/admin/admin.go b/admin/admin.go index a47a52a..a860cf6 100644 --- a/admin/admin.go +++ b/admin/admin.go @@ -65,6 +65,12 @@ func getServerConfigure(c *gin.Context) { http.NotFound(c.Writer, c.Request) } } +func listConfig(c *gin.Context) { + data := model.GetConfig().Servers + // c.JSON(http.StatusOK, server.NewSuccessResult(data)) + + c.JSON(http.StatusOK, server.NewResultObj(data)) +} func getStatus(c *gin.Context) { runtime := runtime.NumGoroutine() @@ -131,6 +137,7 @@ func InitAdminApi(conf *model.HttpServerConfig) { configGroup := api.Group("config") { configGroup.POST("", setConfig) + configGroup.GET("", listConfig) configGroup.GET(":name", getServerConfigure) } diff --git a/adminui/js/app.js b/adminui/js/app.js index 0925781..d5ecf28 100644 --- a/adminui/js/app.js +++ b/adminui/js/app.js @@ -7,13 +7,13 @@ new Vue({ serverConfig: JSON.parse(localStorage.getItem('serverConfig')) || { sites: [ { - id: Date.now(), + name: '示例网站', - domain: 'example.com', + server: 'example.com', port: 8080, - ssl: false, + enable_ssl: false, collapsed: false, - routes: [ + paths: [ { path: '/static', type: 'static', @@ -186,6 +186,17 @@ new Vue({ }); }, + //get site + getSites() { + //visit REST API to get sites, url is /api/config + //return this.serverConfig.sites; + this.$axios.get('/api/config').then(response => { + this.sites = response.data; + this.siteIndex = siteIndex; + this.getRoutes(siteIndex); + }); + + }, // 路由管理 addRoute(siteIndex) { this.routeDialog = { diff --git a/config.json b/config.json index 65fbdbc..1ac9973 100644 --- a/config.json +++ b/config.json @@ -23,7 +23,7 @@ }, "admin": { "name": "admin", - "server":"admin", + "server":"localhost", "port": 8088, "username": "admin", "password": "admin", diff --git a/server/result.go b/server/result.go index 470f38f..1ff29b7 100644 --- a/server/result.go +++ b/server/result.go @@ -34,3 +34,10 @@ func NewSuccessResult(data interface{}) []byte { ret, _ := json.Marshal(result) return ret } + +func NewResultObj(data interface{}) RestResult { + result := ResultSuccess + result.Data = data + + return result +}