From 94cc9e3e2eaa163f277c69f6842f91d6e906d2c8 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Sun, 14 Apr 2024 09:19:36 +0000 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=89=93=E5=8C=85=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-latest-backend.yaml | 11 +++++++++++ Dockerfile | 1 + backend/controller/api.go | 10 ++++++++++ backend/database/po.go | 1 + 4 files changed, 23 insertions(+) diff --git a/.github/workflows/build-latest-backend.yaml b/.github/workflows/build-latest-backend.yaml index 9ca4e70..f8dacb5 100644 --- a/.github/workflows/build-latest-backend.yaml +++ b/.github/workflows/build-latest-backend.yaml @@ -21,10 +21,21 @@ jobs: uses: actions/setup-go@v2 with: go-version: 1.22.1 + + - name: Set up Node.js 20.12 + uses: actions/setup-node@v2 + with: + node-version: 20.12 - name: Build the backend run: | go build -o bin/campux main.go + + - name: Build the frontend + run: | + cd frontend + npm install + npm run build - name: Log in to the Container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 diff --git a/Dockerfile b/Dockerfile index 6922f25..49e8782 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM golang:1.22.1 WORKDIR /app COPY bin/campux /app/campux +COPY frontend/dist /app/frontend/dist EXPOSE 8080 diff --git a/backend/controller/api.go b/backend/controller/api.go index 36cb2f2..950365f 100644 --- a/backend/controller/api.go +++ b/backend/controller/api.go @@ -1,6 +1,8 @@ package controller import ( + "net/http" + "strings" "time" "github.com/RockChinQ/Campux/backend/service" @@ -37,6 +39,14 @@ func NewApiController( ) } + r.Use(func(c *gin.Context) { + if strings.HasPrefix(c.Request.URL.Path, "/v1") { + c.Next() + return + } + http.ServeFile(c.Writer, c.Request, "./frontend/dist"+c.Request.URL.Path) + }) + rg := r.Group("/v1") // bind routes diff --git a/backend/database/po.go b/backend/database/po.go index d0db6a2..61946a9 100644 --- a/backend/database/po.go +++ b/backend/database/po.go @@ -7,6 +7,7 @@ import ( type UserGroup string const ( + USER_GROUP_ANY UserGroup = "any" USER_GROUP_ADMIN UserGroup = "admin" USER_GROUP_MEMBER UserGroup = "member" USER_GROUP_USER UserGroup = "user"