You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/10/24 03:23:44 UTC
[apisix-dashboard] branch master updated: feat: add file server
(#594)
This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 462b552 feat: add file server (#594)
462b552 is described below
commit 462b552bc5ddb182946ab48a638ab84bdc9ac888
Author: Vinci Xu <27...@qq.com>
AuthorDate: Sat Oct 24 11:23:35 2020 +0800
feat: add file server (#594)
* feat: add file server
* dock: add descrition for file server
---
api/Dockerfile | 1 +
api/conf/conf.go | 26 +++++++++++++++-----------
api/dist/.gitkeep | 0
api/go.mod | 1 +
api/go.sum | 6 ++++++
api/internal/route.go | 8 +++++++-
api/log/log.go | 2 +-
api/main.go | 1 -
docs/deploy.md | 4 ++--
docs/deploy.zh-CN.md | 5 ++---
10 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/api/Dockerfile b/api/Dockerfile
index 1af2ba0..1c8574a 100644
--- a/api/Dockerfile
+++ b/api/Dockerfile
@@ -64,6 +64,7 @@ RUN cd /go/manager-api/build-tools \
&& lua schema-sync.lua > /go/manager-api/schema.json \
&& cd /go/manager-api/ \
&& rm -rf /go/manager-api/build-tools/
+ADD ./dist /go/manager-api
EXPOSE 8080
diff --git a/api/conf/conf.go b/api/conf/conf.go
index 328cddc..84c509f 100644
--- a/api/conf/conf.go
+++ b/api/conf/conf.go
@@ -28,14 +28,18 @@ import (
"github.com/apisix/manager-api/internal/utils"
)
-const ServerPort = 8080
-const PROD = "prod"
-const BETA = "beta"
-const DEV = "dev"
-const LOCAL = "local"
-const confPath = "/go/manager-api/conf.json"
-const schemaPath = "/go/manager-api/schema.json"
-const RequestId = "requestId"
+const (
+ ServerPort = 8080
+ WebDir = "./dist"
+
+ EnvPROD = "prod"
+ EnvBETA = "beta"
+ EnvDEV = "dev"
+ EnvLOCAL = "local"
+
+ confPath = "/go/manager-api/conf.json"
+ schemaPath = "/go/manager-api/schema.json"
+)
var (
ENV string
@@ -52,7 +56,7 @@ func init() {
func setEnvironment() {
if env := os.Getenv("ENV"); env == "" {
- ENV = LOCAL
+ ENV = EnvLOCAL
} else {
ENV = env
}
@@ -65,7 +69,7 @@ func setEnvironment() {
}
func configurationPath() string {
- if ENV == LOCAL {
+ if ENV == EnvLOCAL {
return filepath.Join(filepath.Dir(basePath), "conf.json")
} else {
return confPath
@@ -73,7 +77,7 @@ func configurationPath() string {
}
func getSchemaPath() string {
- if ENV == LOCAL {
+ if ENV == EnvLOCAL {
return filepath.Join(filepath.Dir(basePath), "schema.json")
} else {
return schemaPath
diff --git a/api/dist/.gitkeep b/api/dist/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/api/go.mod b/api/go.mod
index bcec2f1..3f41ce6 100644
--- a/api/go.mod
+++ b/api/go.mod
@@ -13,6 +13,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-contrib/pprof v1.3.0
github.com/gin-contrib/sessions v0.0.3
+ github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e
github.com/gin-gonic/gin v1.6.3
github.com/gogo/protobuf v1.3.1 // indirect
github.com/google/uuid v1.1.2 // indirect
diff --git a/api/go.sum b/api/go.sum
index 0fce5c9..37089e0 100644
--- a/api/go.sum
+++ b/api/go.sum
@@ -51,6 +51,7 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
+github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@@ -63,6 +64,8 @@ github.com/gin-contrib/sessions v0.0.3 h1:PoBXki+44XdJdlgDqDrY5nDVe3Wk7wDV/UCOuL
github.com/gin-contrib/sessions v0.0.3/go.mod h1:8C/J6cad3Il1mWYYgtw0w+hqasmpvy25mPkXdOgeB9I=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
+github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e h1:8bZpGwoPxkaivQPrAbWl+7zjjUcbFUnYp7yQcx2r2N0=
+github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e/go.mod h1:VhW/Ch/3FhimwZb8Oj+qJmdMmoB8r7lmJ5auRjm50oQ=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
@@ -138,6 +141,7 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
+github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
@@ -174,8 +178,10 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
diff --git a/api/internal/route.go b/api/internal/route.go
index 9814620..0304605 100644
--- a/api/internal/route.go
+++ b/api/internal/route.go
@@ -17,9 +17,11 @@
package internal
import (
+ "fmt"
"github.com/gin-contrib/pprof"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
+ "github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/apisix/manager-api/conf"
@@ -36,7 +38,7 @@ import (
)
func SetUpRouter() *gin.Engine {
- if conf.ENV != conf.LOCAL && conf.ENV != conf.BETA {
+ if conf.ENV != conf.EnvLOCAL && conf.ENV != conf.EnvBETA {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
@@ -45,6 +47,10 @@ func SetUpRouter() *gin.Engine {
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("session", store))
r.Use(filter.CORS(), filter.Authentication(), filter.RequestId(), filter.RecoverHandler())
+ r.Use(static.Serve("/", static.LocalFile(conf.WebDir, false)))
+ r.NoRoute(func(c *gin.Context) {
+ c.File(fmt.Sprintf("%s/index.html", conf.WebDir))
+ })
factories := []handler.RegisterFactory{
route.NewHandler,
diff --git a/api/log/log.go b/api/log/log.go
index ea34643..b9e6860 100644
--- a/api/log/log.go
+++ b/api/log/log.go
@@ -89,7 +89,7 @@ func GetLogger() *logrus.Entry {
var log = logrus.New()
setNull(log)
log.SetLevel(logrus.DebugLevel)
- if conf.ENV != conf.LOCAL {
+ if conf.ENV != conf.EnvLOCAL {
log.SetLevel(logrus.ErrorLevel)
}
log.SetFormatter(&logrus.JSONFormatter{})
diff --git a/api/main.go b/api/main.go
index 2975b34..2e24fd2 100644
--- a/api/main.go
+++ b/api/main.go
@@ -43,7 +43,6 @@ func main() {
if err := store.InitStores(); err != nil {
panic(err)
}
-
// routes
r := internal.SetUpRouter()
addr := fmt.Sprintf(":%d", conf.ServerPort)
diff --git a/docs/deploy.md b/docs/deploy.md
index 41deb47..53ebad1 100644
--- a/docs/deploy.md
+++ b/docs/deploy.md
@@ -83,5 +83,5 @@ $ yarn install
$ yarn build
```
-5. The bundled files are under `/dist` folder if the step 4 is successful, then we recommend using `nginx` to handle those files, please install `nginx` manually, then refer to the nginx conf `compose/dashboard_conf/nginx.conf`.
-6. Move files under `dist` folder to nginx's default html folder, then visit `http://127.0.0.1` in your browser.
+5. The bundled files are under `/dist` folder if the step 4 is successful.
+6. Move files under `dist` folder to manager-api's `dist` folder, then visit `http://127.0.0.1:8080` in your browser, `8080` is the default listen port of manager-api.
diff --git a/docs/deploy.zh-CN.md b/docs/deploy.zh-CN.md
index ceeefc4..01c2159 100644
--- a/docs/deploy.zh-CN.md
+++ b/docs/deploy.zh-CN.md
@@ -85,6 +85,5 @@ $ yarn install
$ yarn build
```
-5. 如果第 4 步成功的话,那么构建后的文件在 `/dist` 目录下,接着我们推荐使用 `nginx` 处理这些文件,请手动安装 `nginx` 并参考 `compose/dashboard_conf/nginx.conf` 配置。
-
-6. 移动 `dist` 目录下的文件到 nginx 的默认 html 目录,然后在浏览器中访问 `http://127.0.0.1`。
+5. 如果第 4 步成功的话,那么构建后的文件在 `/dist` 目录下。
+6. 移动 `dist` 目录下的文件到 manager-api 的 `dist` 目录下,然后在浏览器中访问 `http://127.0.0.1:8080`,`8080` 是 manager-api 的默认监听端口。