MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / createProxyFile

Function createProxyFile

agent/app/service/website_utils.go:176–207  ·  view source on GitHub ↗
(website *model.Website)

Source from the content-addressed store, hash-verified

174}
175
176func createProxyFile(website *model.Website) error {
177 proxyFolder := GetSitePath(*website, SiteProxyDir)
178 filePath := path.Join(proxyFolder, "root.conf")
179 fileOp := files.NewFileOp()
180 if !fileOp.Stat(proxyFolder) {
181 if err := fileOp.CreateDir(proxyFolder, constant.DirPerm); err != nil {
182 return err
183 }
184 }
185 if !fileOp.Stat(filePath) {
186 if err := fileOp.CreateFile(filePath); err != nil {
187 return err
188 }
189 }
190 config, err := parser.NewStringParser(string(nginx_conf.Proxy)).Parse()
191 if err != nil {
192 return err
193 }
194 config.FilePath = filePath
195 directives := config.Directives
196 location, ok := directives[0].(*components.Location)
197 if !ok {
198 return errors.New("error")
199 }
200 location.ChangePath("^~", "/")
201 applyLocationProxyPass(location, website.Proxy, nil, "")
202 location.UpdateDirective("proxy_set_header", []string{"Host", "$host"})
203 if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
204 return buserr.WithErr("ErrUpdateBuWebsite", err)
205 }
206 return nil
207}
208
209func createWebsiteFolder(website *model.Website, runtime *model.Runtime) error {
210 siteFolder := GetSiteDir(website.Alias)

Callers 1

createWebsiteFolderFunction · 0.85

Calls 8

StatMethod · 0.95
CreateDirMethod · 0.95
CreateFileMethod · 0.95
GetSitePathFunction · 0.85
applyLocationProxyPassFunction · 0.85
ParseMethod · 0.80
ChangePathMethod · 0.80
UpdateDirectiveMethod · 0.65

Tested by

no test coverage detected