|
1 | 1 | package server
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 | 4 | "log"
|
6 | 5 |
|
7 | 6 | "github.com/charmbracelet/soft/config"
|
8 | 7 | appCfg "github.com/charmbracelet/soft/internal/config"
|
9 |
| - "github.com/charmbracelet/soft/internal/tui" |
10 |
| - |
11 |
| - "github.com/charmbracelet/wish" |
12 |
| - bm "github.com/charmbracelet/wish/bubbletea" |
13 |
| - gm "github.com/charmbracelet/wish/git" |
14 |
| - lm "github.com/charmbracelet/wish/logging" |
15 |
| - "github.com/gliderlabs/ssh" |
16 | 8 | )
|
17 | 9 |
|
18 | 10 | type Server struct {
|
19 |
| - SSHServer *ssh.Server |
20 |
| - Config *config.Config |
21 |
| - config *appCfg.Config |
| 11 | + HTTPServer *HTTPServer |
| 12 | + SSHServer *SSHServer |
| 13 | + Config *config.Config |
| 14 | + ac *appCfg.Config |
22 | 15 | }
|
23 | 16 |
|
24 |
| -// NewServer returns a new *ssh.Server configured to serve Soft Serve. The SSH |
25 |
| -// server key-pair will be created if none exists. An initial admin SSH public |
26 |
| -// key can be provided with authKey. If authKey is provided, access will be |
27 |
| -// restricted to that key. If authKey is not provided, the server will be |
28 |
| -// publicly writable until configured otherwise by cloning the `config` repo. |
29 | 17 | func NewServer(cfg *config.Config) *Server {
|
30 | 18 | ac, err := appCfg.NewConfig(cfg)
|
31 | 19 | if err != nil {
|
32 | 20 | log.Fatal(err)
|
33 | 21 | }
|
34 |
| - mw := []wish.Middleware{ |
35 |
| - bm.Middleware(tui.SessionHandler(ac)), |
36 |
| - gm.Middleware(cfg.RepoPath, ac), |
37 |
| - lm.Middleware(), |
38 |
| - } |
39 |
| - s, err := wish.NewServer( |
40 |
| - ssh.PublicKeyAuth(ac.PublicKeyHandler), |
41 |
| - ssh.PasswordAuth(ac.PasswordHandler), |
42 |
| - wish.WithAddress(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)), |
43 |
| - wish.WithHostKeyPath(cfg.KeyPath), |
44 |
| - wish.WithMiddleware(mw...), |
45 |
| - ) |
46 |
| - if err != nil { |
47 |
| - log.Fatalln(err) |
48 |
| - } |
49 | 22 | return &Server{
|
50 |
| - SSHServer: s, |
51 |
| - Config: cfg, |
52 |
| - config: ac, |
| 23 | + HTTPServer: NewHTTPServer(cfg, ac), |
| 24 | + SSHServer: NewSSHServer(cfg, ac), |
| 25 | + Config: cfg, |
| 26 | + ac: ac, |
53 | 27 | }
|
54 | 28 | }
|
55 | 29 |
|
56 | 30 | func (srv *Server) Reload() error {
|
57 |
| - return srv.config.Reload() |
| 31 | + return srv.ac.Reload() |
58 | 32 | }
|
59 | 33 |
|
60 | 34 | func (srv *Server) Start() error {
|
61 |
| - return srv.SSHServer.ListenAndServe() |
| 35 | + go func() { |
| 36 | + if err := srv.HTTPServer.Start(); err != nil { |
| 37 | + log.Fatal(err) |
| 38 | + } |
| 39 | + }() |
| 40 | + return srv.SSHServer.Start() |
62 | 41 | }
|
0 commit comments