···1212 "github.com/pomdtr/smallweb/api"
1313 "github.com/pomdtr/smallweb/app"
1414 "github.com/pomdtr/smallweb/database"
1515- "github.com/pomdtr/smallweb/utils"
1615 "github.com/spf13/cobra"
1716)
1817···2221 Short: "Start a tunnel to a remote server (powered by localhost.run)",
2322 GroupID: CoreGroupID,
2423 Args: cobra.ExactArgs(1),
2525- ValidArgsFunction: completeApp(utils.ExpandTilde(k.String("dir"))),
2424+ ValidArgsFunction: completeApp(k.String("dir")),
2625 RunE: func(cmd *cobra.Command, args []string) error {
2726 db, err := database.OpenDB(filepath.Join(DataDir(), "smallweb.db"))
2827 if err != nil {
···37363837 server := http.Server{
3938 Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4040- rootDir := utils.ExpandTilde(k.String("dir"))
3939+ rootDir := k.String("dir")
4140 app, err := app.LoadApp(filepath.Join(rootDir, args[0]), k.String("domain"))
4241 if err != nil {
4342 w.WriteHeader(http.StatusNotFound)
+18-12
cmd/up.go
···5353 cronWriter := utils.NewMultiWriter()
5454 consoleWriter := utils.NewMultiWriter()
55555656- httpLogger := utils.NewLogger(httpWriter)
5756 consoleLogger := slog.New(slog.NewJSONHandler(consoleWriter, nil))
58575958 apiHandler := api.NewHandler(k, httpWriter, cronWriter, consoleWriter)
6059 appHandler := &AppHandler{apiServer: apiHandler, db: db, logger: consoleLogger}
6160 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6262- rootDir := utils.ExpandTilde(k.String("dir"))
6161+ rootDir := k.String("dir")
63626463 if r.Host == k.String("domain") {
6564 // if we are on the apex domain and www exists, redirect to www
···9493 appHandler.ServeApp(w, r, a)
9594 })
96959797- addr := fmt.Sprintf("%s:%d", k.String("host"), k.Int("port"))
9898- server := http.Server{
9999- Addr: addr,
100100- Handler: httpLogger.Middleware(handler),
101101- }
102102-10396 parser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor)
10497 c := cron.New(cron.WithParser(parser))
10598 cronLogger := slog.New(slog.NewJSONHandler(cronWriter, nil))
10699 c.AddFunc("* * * * *", func() {
107100 rounded := time.Now().Truncate(time.Minute)
108108- rootDir := utils.ExpandTilde(k.String("dir"))
101101+ rootDir := k.String("dir")
109102 apps, err := app.ListApps(rootDir)
110103 if err != nil {
111104 fmt.Println(err)
···167160168161 go c.Start()
169162170170- fmt.Fprintf(os.Stderr, "Serving *.%s from %s on %s\n", k.String("domain"), k.String("dir"), addr)
171171- go server.ListenAndServe()
163163+ fmt.Fprintf(os.Stderr, "Serving *.%s from %s on %s\n", k.String("domain"), k.String("dir"), k.String("addr"))
164164+ httpLogger := utils.NewLogger(httpWriter)
165165+ server := http.Server{
166166+ Handler: httpLogger.Middleware(handler),
167167+ }
168168+169169+ addr := k.String("addr")
170170+ var ln net.Listener
171171+ if strings.HasPrefix(addr, "unix/") {
172172+ socketPath := strings.TrimPrefix(addr, "unix/")
173173+ net.Listen("unix", utils.ExpandTilde(socketPath))
174174+ } else {
175175+ net.Listen("tcp", addr)
176176+ }
177177+178178+ go server.Serve(ln)
172179173180 // start api server on unix socket
174181 apiServer := http.Server{
···202209 <-sigint
203210204211 log.Println("Shutting down server...")
205205- server.Shutdown(context.Background())
206212 apiServer.Shutdown(context.Background())
207213 c.Stop()
208214 return nil
+8-11
docs/src/reference/global_config.md
···8899## Available Fields
10101111-### `host`
1111+### `addr`
12121313-The `host` field defines the host to bind to. By default, it is `127.0.0.1`.
1313+The `addr` field defines the addr to bind to. By default, it is `:7777`.
14141515```json
1616{
1717- "host": "0.0.0.0"
1717+ "addr": "127.0.0.1:8000"
1818}
1919```
20202121-### `port`
2222-2323-The `port` field defines the port to bind to. By default, it is `7777`.
2121+If you want to use an unix socket, you can use the `unix/` prefix.
24222523```json
2624{
2727- "port": 8000
2525+ "addr": "unix/~/smallweb.sock"
2826}
2927```
3028···68666967```json
7068{
7171- "host": "127.0.0.1",
7272- "port": 7777,
6969+ "addr": ":7777",
7370 "dir": "~/smallweb",
7471}
7572```
···8784```json
8885{
8986 "domain": "example.com",
9090- "host": "127.0.0.1",
9191- "port": 7777,
8787+ "addr": ":7777",
9288 "dir": "~/smallweb",
9389}
9090+```