mirror of
https://github.com/kopia/kopia.git
synced 2026-01-22 21:38:06 -05:00
This is enabled by `kopia server --ui` and can be viewed in a browser at http://localhost:51515/ Right now it can only list snapshots and policies (barely).
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/internal/server"
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
var (
|
|
serverAddress = serverCommands.Flag("address", "Server address").Default("127.0.0.1:51515").String()
|
|
|
|
serverStartCommand = serverCommands.Command("start", "Start Kopia server").Default()
|
|
serverStartHTMLPath = serverStartCommand.Flag("html", "Server the provided HTML at the root URL").ExistingDir()
|
|
serverStartUI = serverStartCommand.Flag("ui", "Start the server with HTML UI (EXPERIMENTAL)").Bool()
|
|
)
|
|
|
|
func init() {
|
|
serverStartCommand.Action(repositoryAction(runServer))
|
|
}
|
|
|
|
func runServer(ctx context.Context, rep *repo.Repository) error {
|
|
srv, err := server.New(ctx, rep, getHostName(), getUserName())
|
|
if err != nil {
|
|
return errors.Wrap(err, "unable to initialize server")
|
|
}
|
|
|
|
go rep.RefreshPeriodically(ctx, 10*time.Second)
|
|
|
|
url := "http://" + *serverAddress
|
|
log.Infof("starting server on %v", url)
|
|
http.Handle("/api/", srv.APIHandlers())
|
|
if *serverStartHTMLPath != "" {
|
|
fileServer := http.FileServer(http.Dir(*serverStartHTMLPath))
|
|
http.Handle("/", fileServer)
|
|
} else if *serverStartUI {
|
|
http.Handle("/", http.FileServer(server.AssetFile()))
|
|
}
|
|
return http.ListenAndServe(*serverAddress, nil)
|
|
}
|