mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* feat: Add v1 schema types This adds compatibility for sharing data with Coder v1. Since the tables are the same, all CRUD operations should function as expected. * Add license table * feat: Add Coder Daemon to serve the API coderd is a public package which will be consumed by v1 to support running both at the same time. The frontend will need to be compiled and statically served as part of this eventually. * Fix initial migration * Move to /api/v2 * Increase peer disconnectedTimeout to reduce flakes on slow machines * Reduce timeout again * Fix version for pion/ice
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"os"
|
|
|
|
"cdr.dev/slog"
|
|
"cdr.dev/slog/sloggers/sloghuman"
|
|
"github.com/coder/coder/coderd"
|
|
"github.com/coder/coder/database"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
func Root() *cobra.Command {
|
|
var (
|
|
address string
|
|
)
|
|
root := &cobra.Command{
|
|
Use: "coderd",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
handler := coderd.New(&coderd.Options{
|
|
Logger: slog.Make(sloghuman.Sink(os.Stderr)),
|
|
Database: database.NewInMemory(),
|
|
})
|
|
|
|
listener, err := net.Listen("tcp", address)
|
|
if err != nil {
|
|
return xerrors.Errorf("listen %q: %w", address, err)
|
|
}
|
|
defer listener.Close()
|
|
|
|
errCh := make(chan error)
|
|
go func() {
|
|
defer close(errCh)
|
|
errCh <- http.Serve(listener, handler)
|
|
}()
|
|
|
|
select {
|
|
case <-cmd.Context().Done():
|
|
return cmd.Context().Err()
|
|
case err := <-errCh:
|
|
return err
|
|
}
|
|
},
|
|
}
|
|
defaultAddress, ok := os.LookupEnv("ADDRESS")
|
|
if !ok {
|
|
defaultAddress = "127.0.0.1:3000"
|
|
}
|
|
root.Flags().StringVarP(&address, "address", "a", defaultAddress, "The address to serve the API and dashboard.")
|
|
|
|
return root
|
|
}
|