(id uint)
| 260 | } |
| 261 | |
| 262 | func (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 |
no test coverage detected