mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-29 05:49:07 +08:00
fix: 解决静态网站创建失败的BUG
This commit is contained in:
parent
6593c6de66
commit
a914d29961
@ -92,6 +92,8 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
||||
Proxy: create.Proxy,
|
||||
}
|
||||
|
||||
tx, ctx := getTxAndContext()
|
||||
|
||||
switch create.Type {
|
||||
case constant.Deployment:
|
||||
if create.AppType == constant.NewApp {
|
||||
@ -99,19 +101,14 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
||||
req.Name = create.AppInstall.Name
|
||||
req.AppDetailId = create.AppInstall.AppDetailId
|
||||
req.Params = create.AppInstall.Params
|
||||
install, err := ServiceGroupApp.Install(context.Background(), req)
|
||||
install, err := ServiceGroupApp.Install(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
website.AppInstallID = install.ID
|
||||
}
|
||||
case constant.Static:
|
||||
if err := createStaticHtml(website); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
tx, ctx := getTxAndContext()
|
||||
if err := websiteRepo.Create(ctx, website); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -94,6 +94,11 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website)
|
||||
if err := fileOp.CreateDir(path.Join(siteFolder, "ssl"), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if website.Type == constant.Static {
|
||||
if err := createStaticHtml(website); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileOp.CopyDir(path.Join(nginxFolder, "www", "common", "waf", "rules"), path.Join(siteFolder, "waf"))
|
||||
}
|
||||
@ -151,9 +156,15 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) e
|
||||
}
|
||||
|
||||
if err := opNginx(nginxInstall.ContainerName, constant.NginxCheck); err != nil {
|
||||
_ = deleteWebsiteFolder(nginxInstall, website)
|
||||
return err
|
||||
}
|
||||
return opNginx(nginxInstall.ContainerName, constant.NginxReload)
|
||||
if err := opNginx(nginxInstall.ContainerName, constant.NginxReload); err != nil {
|
||||
_ = deleteWebsiteFolder(nginxInstall, website)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func delNginxConfig(website model.Website, force bool) error {
|
||||
@ -564,3 +575,17 @@ func copyConf(srcPath, dstPath string) error {
|
||||
_, _ = io.Copy(out, src)
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error {
|
||||
nginxFolder := path.Join(constant.AppInstallDir, constant.AppNginx, nginxInstall.Name)
|
||||
siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias)
|
||||
fileOp := files.NewFileOp()
|
||||
if fileOp.Stat(siteFolder) {
|
||||
_ = fileOp.DeleteDir(siteFolder)
|
||||
}
|
||||
nginxFilePath := path.Join(nginxFolder, "conf", "conf.d", website.PrimaryDomain+".conf")
|
||||
if fileOp.Stat(nginxFilePath) {
|
||||
_ = fileOp.DeleteFile(nginxFilePath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user