@cryptotaxi247 / kubo / commits / 7c5b27617

cmd/ipfs: daemon: Added root redirect handler to corehttp options (for both gateway and API)

Matt Bell committed Jan 26, 2015 at 23:18 UTC 7c5b276179e41d747eb0ddf9c4f5a17002add8b1
1 file changed +13 -1
cmd/ipfs/daemon.go
+13 -1
@@ -153,9 +153,18 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
153 fmt.Printf("IPNS mounted at: %s\n", nsdir)
154 }
155
156 + var rootRedirect corehttp.ServeOption
157 + if len(cfg.Gateway.RootRedirect) > 0 {
158 + rootRedirect = corehttp.RedirectOption("", cfg.Gateway.RootRedirect)
159 + }
160 +
161 if gatewayMaddr != nil {
162 go func() {
158 - err := corehttp.ListenAndServe(node, gatewayMaddr.String(), corehttp.GatewayOption)
163 + var opts = []corehttp.ServeOption{corehttp.GatewayOption}
164 + if rootRedirect != nil {
165 + opts = append(opts, rootRedirect)
166 + }
167 + err := corehttp.ListenAndServe(node, gatewayMaddr.String(), opts...)
168 if err != nil {
169 log.Error(err)
170 }
@@ -167,6 +176,9 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
176 corehttp.WebUIOption,
177 corehttp.GatewayOption,
178 }
179 + if rootRedirect != nil {
180 + opts = append(opts, rootRedirect)
181 + }
182 if err := corehttp.ListenAndServe(node, apiMaddr.String(), opts...); err != nil {
183 res.SetError(err, cmds.ErrNormal)
184 return