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

Method GetProxies

agent/app/service/website_proxy.go:262–352  ·  view source on GitHub ↗
(id uint)

Source from the content-addressed store, hash-verified

260}
261
262func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, err error) {
263 var (
264 website model.Website
265 fileList response.FileInfo
266 )
267 website, err = websiteRepo.GetFirst(repo.WithByID(id))
268 if err != nil {
269 return
270 }
271 includeDir := GetSitePath(website, SiteProxyDir)
272 fileOp := files.NewFileOp()
273 if !fileOp.Stat(includeDir) {
274 return
275 }
276 fileList, err = NewIFileService().GetFileList(request.FileOption{FileOption: files.FileOption{Path: includeDir, Expand: true, Page: 1, PageSize: 100}})
277 if len(fileList.Items) == 0 {
278 return
279 }
280 var (
281 content []byte
282 config *components.Config
283 )
284 for _, configFile := range fileList.Items {
285 proxyConfig := request.WebsiteProxyConfig{
286 ID: website.ID,
287 }
288 parts := strings.Split(configFile.Name, ".")
289 proxyConfig.Name = parts[0]
290 if parts[1] == "conf" {
291 proxyConfig.Enable = true
292 } else {
293 proxyConfig.Enable = false
294 }
295 proxyConfig.FilePath = configFile.Path
296 content, err = fileOp.GetContent(configFile.Path)
297 if err != nil {
298 return
299 }
300 proxyConfig.Content = string(content)
301 config, err = parser.NewStringParser(string(content)).Parse()
302 if err != nil {
303 return nil, err
304 }
305 directives := config.GetDirectives()
306
307 var location *components.Location
308 for _, directive := range directives {
309 if loc, ok := directive.(*components.Location); ok {
310 location = loc
311 break
312 }
313 }
314 if location == nil {
315 err = errors.New("invalid proxy config, no location found")
316 return
317 }
318 proxyConfig.ProxyPass = location.ProxyPass
319 proxyConfig.Cache = location.Cache

Callers 1

DeleteLoadBalanceMethod · 0.95

Calls 11

StatMethod · 0.95
GetContentMethod · 0.95
GetSitePathFunction · 0.85
NewIFileServiceFunction · 0.85
ParseMethod · 0.80
GetFirstMethod · 0.65
WithByIDMethod · 0.65
GetFileListMethod · 0.65
GetDirectivesMethod · 0.65
GetNameMethod · 0.65
GetParametersMethod · 0.65

Tested by

no test coverage detected