newMacaron initializes Macaron instance.
()
| 59 | |
| 60 | // newMacaron initializes Macaron instance. |
| 61 | func newMacaron() *macaron.Macaron { |
| 62 | m := macaron.New() |
| 63 | if !conf.Server.DisableRouterLog { |
| 64 | m.Use(macaron.Logger()) |
| 65 | } |
| 66 | m.Use(macaron.Recovery()) |
| 67 | if conf.Server.EnableGzip { |
| 68 | m.Use(gzip.Gziper()) |
| 69 | } |
| 70 | if conf.Server.Protocol == "fcgi" { |
| 71 | m.SetURLPrefix(conf.Server.Subpath) |
| 72 | } |
| 73 | |
| 74 | // Register custom middleware first to make it possible to override files under "public". |
| 75 | m.Use(macaron.Static( |
| 76 | filepath.Join(conf.CustomDir(), "public"), |
| 77 | macaron.StaticOptions{ |
| 78 | SkipLogging: conf.Server.DisableRouterLog, |
| 79 | }, |
| 80 | )) |
| 81 | var publicFs http.FileSystem |
| 82 | if !conf.Server.LoadAssetsFromDisk { |
| 83 | publicFs = http.FS(public.Files) |
| 84 | } |
| 85 | m.Use(macaron.Static( |
| 86 | filepath.Join(conf.WorkDir(), "public"), |
| 87 | macaron.StaticOptions{ |
| 88 | ETag: true, |
| 89 | SkipLogging: conf.Server.DisableRouterLog, |
| 90 | FileSystem: publicFs, |
| 91 | }, |
| 92 | )) |
| 93 | |
| 94 | m.Use(macaron.Static( |
| 95 | conf.Picture.AvatarUploadPath, |
| 96 | macaron.StaticOptions{ |
| 97 | ETag: true, |
| 98 | Prefix: conf.UsersAvatarPathPrefix, |
| 99 | SkipLogging: conf.Server.DisableRouterLog, |
| 100 | }, |
| 101 | )) |
| 102 | m.Use(macaron.Static( |
| 103 | conf.Picture.RepositoryAvatarUploadPath, |
| 104 | macaron.StaticOptions{ |
| 105 | ETag: true, |
| 106 | Prefix: database.RepoAvatarURLPrefix, |
| 107 | SkipLogging: conf.Server.DisableRouterLog, |
| 108 | }, |
| 109 | )) |
| 110 | |
| 111 | customDir := filepath.Join(conf.CustomDir(), "templates") |
| 112 | renderOpt := macaron.RenderOptions{ |
| 113 | Directory: filepath.Join(conf.WorkDir(), "templates"), |
| 114 | AppendDirectories: []string{customDir}, |
| 115 | Funcs: template.FuncMap(), |
| 116 | IndentJSON: macaron.Env != macaron.PROD, |
| 117 | } |
| 118 | if !conf.Server.LoadAssetsFromDisk { |
no test coverage detected