mirror of https://github.com/1Panel-dev/1Panel
fix: 解决静态网站创建失败的BUG
parent
6593c6de66
commit
a914d29961
|
@ -92,6 +92,8 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
||||||
Proxy: create.Proxy,
|
Proxy: create.Proxy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx, ctx := getTxAndContext()
|
||||||
|
|
||||||
switch create.Type {
|
switch create.Type {
|
||||||
case constant.Deployment:
|
case constant.Deployment:
|
||||||
if create.AppType == constant.NewApp {
|
if create.AppType == constant.NewApp {
|
||||||
|
@ -99,19 +101,14 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
|
||||||
req.Name = create.AppInstall.Name
|
req.Name = create.AppInstall.Name
|
||||||
req.AppDetailId = create.AppInstall.AppDetailId
|
req.AppDetailId = create.AppInstall.AppDetailId
|
||||||
req.Params = create.AppInstall.Params
|
req.Params = create.AppInstall.Params
|
||||||
install, err := ServiceGroupApp.Install(context.Background(), req)
|
install, err := ServiceGroupApp.Install(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
website.AppInstallID = install.ID
|
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 {
|
if err := websiteRepo.Create(ctx, website); err != nil {
|
||||||
return err
|
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 {
|
if err := fileOp.CreateDir(path.Join(siteFolder, "ssl"), 0755); err != nil {
|
||||||
return err
|
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"))
|
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 {
|
if err := opNginx(nginxInstall.ContainerName, constant.NginxCheck); err != nil {
|
||||||
|
_ = deleteWebsiteFolder(nginxInstall, website)
|
||||||
return err
|
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 {
|
func delNginxConfig(website model.Website, force bool) error {
|
||||||
|
@ -564,3 +575,17 @@ func copyConf(srcPath, dstPath string) error {
|
||||||
_, _ = io.Copy(out, src)
|
_, _ = io.Copy(out, src)
|
||||||
return nil
|
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