Skip to content

Commit

Permalink
feat: add file server (#594)
Browse files Browse the repository at this point in the history
* feat: add file server

* dock: add descrition for file server
  • Loading branch information
ShiningRush authored Oct 24, 2020
1 parent 62ce9e2 commit 462b552
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 15 additions & 11 deletions api/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +56,7 @@ func init() {

func setEnvironment() {
if env := os.Getenv("ENV"); env == "" {
ENV = LOCAL
ENV = EnvLOCAL
} else {
ENV = env
}
Expand All @@ -65,15 +69,15 @@ func setEnvironment() {
}

func configurationPath() string {
if ENV == LOCAL {
if ENV == EnvLOCAL {
return filepath.Join(filepath.Dir(basePath), "conf.json")
} else {
return confPath
}
}

func getSchemaPath() string {
if ENV == LOCAL {
if ENV == EnvLOCAL {
return filepath.Join(filepath.Dir(basePath), "schema.json")
} else {
return schemaPath
Expand Down
Empty file added api/dist/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 7 additions & 1 deletion api/internal/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion api/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
1 change: 0 additions & 1 deletion api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func main() {
if err := store.InitStores(); err != nil {
panic(err)
}

// routes
r := internal.SetUpRouter()
addr := fmt.Sprintf(":%d", conf.ServerPort)
Expand Down
4 changes: 2 additions & 2 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 2 additions & 3 deletions docs/deploy.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 的默认监听端口。

0 comments on commit 462b552

Please sign in to comment.