This commit is contained in:
23
Dockerfile.v2
Normal file
23
Dockerfile.v2
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM docker.hub.ipao.vip/jrottenberg/ffmpeg:4.4-alpine
|
||||
|
||||
# Set timezone
|
||||
RUN apk add --no-cache tzdata && \
|
||||
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo "Asia/Shanghai" > /etc/timezone && \
|
||||
apk del tzdata && \
|
||||
mkdir -p /app/downloads /app/dist
|
||||
|
||||
COPY backend_v1/build/app /app/app
|
||||
COPY backend_v1/config.prod.toml /app/config.toml
|
||||
COPY frontend/admin/dist /app/dist/admin
|
||||
COPY frontend/wechat/dist /app/dist/wechat
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT ["/app/app"]
|
||||
|
||||
EXPOSE 9888
|
||||
|
||||
VOLUME ["/app/downloads"]
|
||||
|
||||
CMD [ "serve" ]
|
||||
@@ -2,6 +2,8 @@ package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
|
||||
"quyun/v2/app/commands"
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -21,7 +23,9 @@ import (
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||
"github.com/rogeecn/fabfile"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/dig"
|
||||
@@ -86,6 +90,38 @@ func Serve(cmd *cobra.Command, args []string) error {
|
||||
route.Register(group)
|
||||
}
|
||||
|
||||
svc.Http.Engine.Get("/admin*", checkStaticFile(svc.App.DistAdmin))
|
||||
svc.Http.Engine.Get("/*", checkStaticFile(svc.App.DistWeChat))
|
||||
|
||||
return svc.Http.Serve(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func checkStaticFile(rootPath string) func(ctx fiber.Ctx) error {
|
||||
return func(ctx fiber.Ctx) error {
|
||||
f := ctx.Params("*")
|
||||
if f == "/" || f == "" {
|
||||
f = "index.html"
|
||||
}
|
||||
|
||||
checkFiles := []string{f, "index.html"}
|
||||
for _, checkFile := range checkFiles {
|
||||
filePath := filepath.Join(rootPath, checkFile)
|
||||
log.Infof("check file: %s", filePath)
|
||||
file, err := fabfile.Find(filePath)
|
||||
if err != nil {
|
||||
log.Warnf("file not found: %s", filePath)
|
||||
continue
|
||||
}
|
||||
|
||||
ext := filepath.Ext(filePath)
|
||||
mime := mime.TypeByExtension(ext)
|
||||
|
||||
log.Infof("mime type: %s %s", ext, mime)
|
||||
ctx.Set(fiber.HeaderContentType, mime)
|
||||
|
||||
return ctx.SendFile(file)
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ import (
|
||||
|
||||
type PostListQuery struct {
|
||||
*requests.Pagination
|
||||
Keyword *string `query:"keyword"`
|
||||
Status fields.PostStatus `query:"status"`
|
||||
Keyword *string `query:"keyword"`
|
||||
Status *fields.PostStatus `query:"status"`
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ type posts struct {
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) List(ctx fiber.Ctx, query *dto.PostListQuery, user *models.User) (*requests.Pager, error) {
|
||||
query.Status = fields.PostStatusPublished
|
||||
|
||||
query.Status = lo.ToPtr(fields.PostStatusPublished)
|
||||
pager, err := services.Posts.List(ctx, query)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("post list err: %v", err)
|
||||
|
||||
@@ -42,6 +42,11 @@ func (m *posts) List(ctx context.Context, filter *dto.PostListQuery) (*requests.
|
||||
query = query.Where(tbl.Title.Like(keyword))
|
||||
}
|
||||
|
||||
// filter status
|
||||
if filter.Status != nil {
|
||||
query = query.Where(tbl.Status.Eq(*filter.Status))
|
||||
}
|
||||
|
||||
items, cnt, err := query.FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "list post failed")
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/compress"
|
||||
"github.com/gofiber/fiber/v3/middleware/cors"
|
||||
"github.com/gofiber/fiber/v3/middleware/helmet"
|
||||
"github.com/gofiber/fiber/v3/middleware/logger"
|
||||
"github.com/gofiber/fiber/v3/middleware/recover"
|
||||
"github.com/gofiber/fiber/v3/middleware/requestid"
|
||||
@@ -115,17 +114,17 @@ func Provide(opts ...opt.Option) error {
|
||||
},
|
||||
}))
|
||||
|
||||
// basic security + compression
|
||||
engine.Use(helmet.New())
|
||||
engine.Use(compress.New(compress.Config{Level: compress.LevelDefault}))
|
||||
// basic security + compression
|
||||
// engine.Use(helmet.New())
|
||||
|
||||
// optional CORS based on config
|
||||
if config.Cors != nil {
|
||||
corsCfg := buildCORSConfig(config.Cors)
|
||||
if corsCfg != nil {
|
||||
engine.Use(cors.New(*corsCfg))
|
||||
}
|
||||
}
|
||||
// if config.Cors != nil {
|
||||
// corsCfg := buildCORSConfig(config.Cors)
|
||||
// if corsCfg != nil {
|
||||
// engine.Use(cors.New(*corsCfg))
|
||||
// }
|
||||
// }
|
||||
|
||||
// logging with request id and latency
|
||||
engine.Use(logger.New(logger.Config{
|
||||
|
||||
@@ -56,7 +56,7 @@ build_backend() {
|
||||
|
||||
build_image() {
|
||||
log "Building Docker image ${DOCKER_IMAGE}:v2"
|
||||
sudo docker build -f Dockerfile -t "${DOCKER_IMAGE}:v2" "$ROOT_DIR"
|
||||
sudo docker build -f Dockerfile.v2 -t "${DOCKER_IMAGE}:v2" "$ROOT_DIR"
|
||||
}
|
||||
|
||||
export_image() {
|
||||
|
||||
Reference in New Issue
Block a user