feat: 修改 OpenResty 的key 为 openresty

This commit is contained in:
zhengkunwang223 2023-02-22 17:13:08 +08:00 committed by zhengkunwang223
parent 1fa970fbc1
commit 6639192c9a
13 changed files with 66 additions and 63 deletions

View file

@ -7,12 +7,12 @@ import (
"github.com/gin-gonic/gin"
)
// @Tags Nginx
// @Summary Load nginx conf
// @Description 获取 nginx 配置信息
// @Tags OpenResty
// @Summary Load OpenResty conf
// @Description 获取 OpenResty 配置信息
// @Success 200 {object} response.FileInfo
// @Security ApiKeyAuth
// @Router /nginx [get]
// @Router /openResty [get]
func (b *BaseApi) GetNginx(c *gin.Context) {
fileInfo, err := nginxService.GetNginxConfig()
if err != nil {
@ -22,14 +22,14 @@ func (b *BaseApi) GetNginx(c *gin.Context) {
helper.SuccessWithData(c, fileInfo)
}
// @Tags Nginx
// @Summary Load partial nginx conf
// @Description 获取部分 nginx 配置信息
// @Tags OpenResty
// @Summary Load partial OpenResty conf
// @Description 获取部分 OpenResty 配置信息
// @Accept json
// @Param request body request.NginxScopeReq true "request"
// @Success 200 {anrry} response.NginxParam
// @Security ApiKeyAuth
// @Router /nginx/scope [post]
// @Router /openResty/scope [post]
func (b *BaseApi) GetNginxConfigByScope(c *gin.Context) {
var req request.NginxScopeReq
if err := c.ShouldBindJSON(&req); err != nil {
@ -45,14 +45,14 @@ func (b *BaseApi) GetNginxConfigByScope(c *gin.Context) {
helper.SuccessWithData(c, params)
}
// @Tags Nginx
// @Summary Update nginx conf
// @Description 更新 nginx 配置信息
// @Tags OpenResty
// @Summary Update OpenResty conf
// @Description 更新 OpenResty 配置信息
// @Accept json
// @Param request body request.NginxConfigUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /nginx/update [post]
// @Router /openResty/update [post]
// @x-panel-log {"bodyKeys":["websiteId"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"websiteId","isList":false,"db":"websites","output_colume":"primary_domain","output_value":"domain"}],"formatZH":"更新 nginx 配置 [domain]","formatEN":"Update nginx conf [domain]"}
func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) {
var req request.NginxConfigUpdate
@ -67,12 +67,12 @@ func (b *BaseApi) UpdateNginxConfigByScope(c *gin.Context) {
helper.SuccessWithData(c, nil)
}
// @Tags Nginx
// @Summary Load nginx status info
// @Description 获取 nginx 状态信息
// @Tags OpenResty
// @Summary Load OpenResty status info
// @Description 获取 OpenResty 状态信息
// @Success 200 {object} response.NginxStatus
// @Security ApiKeyAuth
// @Router /nginx/status [get]
// @Router /openResty/status [get]
func (b *BaseApi) GetNginxStatus(c *gin.Context) {
res, err := nginxService.GetStatus()
if err != nil {
@ -82,14 +82,14 @@ func (b *BaseApi) GetNginxStatus(c *gin.Context) {
helper.SuccessWithData(c, res)
}
// @Tags Nginx
// @Summary Update nginx conf by upload file
// @Description 上传更新 nginx 配置文件
// @Tags OpenResty
// @Summary Update OpenResty conf by upload file
// @Description 上传更新 OpenResty 配置文件
// @Accept json
// @Param request body request.NginxConfigFileUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /nginx/file [post]
// @Router /openResty/file [post]
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新 nginx 配置","formatEN":"Update nginx conf"}
func (b *BaseApi) UpdateNginxFile(c *gin.Context) {
var req request.NginxConfigFileUpdate

View file

@ -324,7 +324,7 @@ func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error
})
}
}
if app.Key == constant.AppNginx {
if app.Key == constant.AppOpenresty {
websites, _ := websiteRepo.GetBy()
for _, website := range websites {
res = append(res, dto.AppResource{
@ -369,7 +369,7 @@ func (a AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
if key == constant.AppRedis {
filePath = path.Join(filePath, "redis.conf")
}
if key == constant.AppNginx {
if key == constant.AppOpenresty {
filePath = path.Join(filePath, "nginx.conf")
}
contentByte, err := os.ReadFile(filePath)

View file

@ -19,11 +19,11 @@ type NginxService struct {
}
func (n NginxService) GetNginxConfig() (response.FileInfo, error) {
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return response.FileInfo{}, err
}
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "nginx.conf")
configPath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "nginx.conf")
info, err := files.NewFileInfo(files.FileOption{
Path: configPath,
Expand: true,
@ -95,7 +95,7 @@ func (n NginxService) UpdateConfigFile(req request.NginxConfigFileUpdate) error
if err := fileOp.WriteFile(req.FilePath, strings.NewReader(req.Content), 0644); err != nil {
return err
}
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}

View file

@ -20,12 +20,12 @@ import (
func getNginxFull(website *model.Website) (dto.NginxFull, error) {
var nginxFull dto.NginxFull
nginxInstall, err := getAppInstallByKey("nginx")
nginxInstall, err := getAppInstallByKey("openresty")
if err != nil {
return nginxFull, err
}
nginxFull.Install = nginxInstall
nginxFull.Dir = path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
nginxFull.Dir = path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name)
nginxFull.ConfigDir = path.Join(nginxFull.Dir, "conf")
nginxFull.ConfigFile = "nginx.conf"
nginxFull.SiteDir = path.Join(nginxFull.Dir, "www")
@ -47,7 +47,7 @@ func getNginxFull(website *model.Website) (dto.NginxFull, error) {
nginxFull.Website = *website
var siteNginxConfig dto.NginxConfig
nginxFileName := website.Alias + ".conf"
siteConfigPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", nginxFileName)
siteConfigPath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "conf.d", nginxFileName)
siteNginxConfig.FilePath = siteConfigPath
siteNginxContent, err := os.ReadFile(siteConfigPath)
if err != nil {

View file

@ -293,11 +293,11 @@ func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) {
}
res.Website = website
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return res, err
}
sitePath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.Alias)
sitePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias)
res.ErrorLogPath = path.Join(sitePath, "log", "error.log")
res.AccessLogPath = path.Join(sitePath, "log", "access.log")
res.SitePath = sitePath
@ -468,7 +468,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (response.FileInfo
return response.FileInfo{}, err
}
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppOpenresty))
if err != nil {
return response.FileInfo{}, err
}
@ -477,7 +477,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (response.FileInfo
return response.FileInfo{}, err
}
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", website.Alias+".conf")
configPath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "conf.d", website.Alias+".conf")
info, err := files.NewFileInfo(files.FileOption{
Path: configPath,
@ -619,7 +619,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
showErr = false
)
app, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
app, err := appRepo.GetFirst(appRepo.WithKey(constant.AppOpenresty))
if err != nil {
return nil, err
}

View file

@ -92,11 +92,11 @@ func (w WebsiteSSLService) Create(create request.WebsiteSSLCreate) (request.Webs
return res, err
}
case constant.Http:
appInstall, err := getAppInstallByKey(constant.AppNginx)
appInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return request.WebsiteSSLCreate{}, err
}
if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppNginx, appInstall.Name, "root")); err != nil {
if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppOpenresty, appInstall.Name, "root")); err != nil {
return res, err
}
}
@ -160,11 +160,11 @@ func (w WebsiteSSLService) Renew(sslId uint) error {
return err
}
case constant.Http:
appInstall, err := getAppInstallByKey(constant.AppNginx)
appInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}
if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppNginx, appInstall.Name, "root")); err != nil {
if err := client.UseHTTP(path.Join(constant.AppInstallDir, constant.AppOpenresty, appInstall.Name, "root")); err != nil {
return err
}
}
@ -197,7 +197,7 @@ func (w WebsiteSSLService) Renew(sslId uint) error {
}
}
if len(websites) > 0 {
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}

View file

@ -51,12 +51,12 @@ func getDomain(domainStr string, websiteID uint) (model.WebsiteDomain, error) {
}
func createStaticHtml(website *model.Website) error {
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}
indexFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.Alias, "index")
indexFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "index")
indexPath := path.Join(indexFolder, "index.html")
indexContent := string(nginx_conf.Index)
fileOp := files.NewFileOp()
@ -77,7 +77,7 @@ func createStaticHtml(website *model.Website) error {
}
func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error {
nginxFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
nginxFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name)
siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias)
fileOp := files.NewFileOp()
if !fileOp.Stat(siteFolder) {
@ -109,7 +109,7 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website)
}
func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, appInstall *model.AppInstall) error {
nginxInstall, err := getAppInstallByKey(constant.AppNginx)
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}
@ -118,7 +118,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
}
nginxFileName := website.Alias + ".conf"
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", nginxFileName)
configPath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "conf.d", nginxFileName)
nginxContent := string(nginx_conf.WebsiteDefault)
config := parser.NewStringParser(nginxContent).Parse()
servers := config.FindServers()
@ -169,7 +169,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
}
func delNginxConfig(website model.Website, force bool) error {
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppOpenresty))
if err != nil {
return err
}
@ -182,7 +182,7 @@ func delNginxConfig(website model.Website, force bool) error {
}
nginxFileName := website.Alias + ".conf"
configPath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "conf", "conf.d", nginxFileName)
configPath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "conf", "conf.d", nginxFileName)
fileOp := files.NewFileOp()
if !fileOp.Stat(configPath) {
@ -191,7 +191,7 @@ func delNginxConfig(website model.Website, force bool) error {
if err := fileOp.DeleteFile(configPath); err != nil {
return err
}
sitePath := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.PrimaryDomain)
sitePath := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.PrimaryDomain)
if fileOp.Stat(sitePath) {
_ = fileOp.DeleteDir(sitePath)
}
@ -247,7 +247,7 @@ func deleteListenAndServerName(website model.Website, ports []int, domains []str
}
func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error {
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppNginx))
nginxApp, err := appRepo.GetFirst(appRepo.WithKey(constant.AppOpenresty))
if err != nil {
return err
}
@ -256,7 +256,7 @@ func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error {
return err
}
configDir := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name, "www", "sites", website.Alias, "ssl")
configDir := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "ssl")
fileOp := files.NewFileOp()
if !fileOp.Stat(configDir) {
@ -417,7 +417,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
}
global.LOG.Info("put website into tmp dir successful")
nginxInfo, err := appInstallRepo.LoadBaseInfo(constant.AppNginx, "")
nginxInfo, err := appInstallRepo.LoadBaseInfo(constant.AppOpenresty, "")
if err != nil {
return err
}
@ -472,7 +472,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
}
func handleWebsiteRecover(website *model.Website, fileDir string) error {
nginxInfo, err := appInstallRepo.LoadBaseInfo(constant.AppNginx, "")
nginxInfo, err := appInstallRepo.LoadBaseInfo(constant.AppOpenresty, "")
if err != nil {
return err
}
@ -566,7 +566,7 @@ func saveWebsiteJson(website *model.Website, tmpDir string) error {
}
func deleteWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error {
nginxFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
nginxFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name)
siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias)
fileOp := files.NewFileOp()
if fileOp.Stat(siteFolder) {

View file

@ -12,9 +12,9 @@ const (
AppNormal = "Normal"
AppTakeDown = "TakeDown"
AppNginx = "nginx"
AppMysql = "mysql"
AppRedis = "redis"
AppOpenresty = "openresty"
AppMysql = "mysql"
AppRedis = "redis"
)
type AppOperate string

View file

@ -10,7 +10,7 @@ type NginxRouter struct {
}
func (a *NginxRouter) InitNginxRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("nginx")
groupRouter := Router.Group("openresty")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth())
baseApi := v1.ApiGroupApp.BaseApi

View file

@ -3,21 +3,21 @@ import { File } from '../interface/file';
import { Nginx } from '../interface/nginx';
export const GetNginx = () => {
return http.get<File.File>(`/nginx`);
return http.get<File.File>(`/openresty`);
};
export const GetNginxConfigByScope = (req: Nginx.NginxScopeReq) => {
return http.post<Nginx.NginxParam[]>(`/nginx/scope`, req);
return http.post<Nginx.NginxParam[]>(`/openresty/scope`, req);
};
export const UpdateNginxConfigByScope = (req: Nginx.NginxConfigReq) => {
return http.post<any>(`/nginx/update`, req);
return http.post<any>(`/openresty/update`, req);
};
export const GetNginxStatus = () => {
return http.get<Nginx.NginxStatus>(`/nginx/status`);
return http.get<Nginx.NginxStatus>(`/openresty/status`);
};
export const UpdateNginxConfigFile = (req: Nginx.NginxFileUpdate) => {
return http.post<any>(`/nginx/file`, req);
return http.post<any>(`/openresty/file`, req);
};

View file

@ -64,7 +64,7 @@ import { MsgSuccess } from '@/utils/message';
const props = defineProps({
appKey: {
type: String,
default: 'nginx',
default: 'openresty',
},
});

View file

@ -130,7 +130,7 @@
<el-button
v-for="(button, key) in buttons"
:key="key"
:type="!button.disabled ? 'primary' : 'info'"
:type="button.disabled && button.disabled(installed) ? 'info' : 'primary'"
plain
round
size="small"
@ -316,6 +316,9 @@ const buttons = [
click: (row: any) => {
openOperate(row, 'down');
},
disabled: (row: any) => {
return row.status !== 'Running';
},
},
{
label: i18n.global.t('app.delete'),

View file

@ -11,7 +11,7 @@
<LayoutContent :title="$t('website.website')" v-loading="loading">
<template #app>
<AppStatus
:app-key="'nginx'"
:app-key="'openresty'"
@setting="setting"
v-model:loading="loading"
@is-exist="checkExist"