forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
67 lines (57 loc) · 1.47 KB
/
serve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"log"
"net/http"
"github.com/joranmulderij/pocketbase/apis"
"github.com/joranmulderij/pocketbase/core"
"github.com/spf13/cobra"
)
// NewServeCommand creates and returns new command responsible for
// starting the default PocketBase web server.
func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
var allowedOrigins []string
var tlsOrigins []string
var httpAddr string
var httpsAddr string
command := &cobra.Command{
Use: "serve",
Short: "Starts the web server (default to 127.0.0.1:8090)",
Run: func(command *cobra.Command, args []string) {
_, err := apis.Serve(app, apis.ServeConfig{
HttpAddr: httpAddr,
HttpsAddr: httpsAddr,
ShowStartBanner: showStartBanner,
AllowedOrigins: allowedOrigins,
TLSOrigins: tlsOrigins,
})
if err != http.ErrServerClosed {
log.Fatalln(err)
}
},
}
command.PersistentFlags().StringSliceVar(
&allowedOrigins,
"origins",
[]string{"*"},
"CORS allowed domain origins list",
)
command.PersistentFlags().StringSliceVar(
&tlsOrigins,
"tls-origins",
[]string{},
"TLS allowed domain origins list",
)
command.PersistentFlags().StringVar(
&httpAddr,
"http",
"127.0.0.1:8090",
"api HTTP server address",
)
command.PersistentFlags().StringVar(
&httpsAddr,
"https",
"",
"api HTTPS server address (auto TLS via Let's Encrypt)\nthe incoming --http address traffic also will be redirected to this address",
)
return command
}