-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
78 lines (61 loc) · 1.78 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
68
69
70
71
72
73
74
75
76
77
78
package app
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/readeck/readeck/configs"
"github.com/readeck/readeck/internal/admin"
"github.com/readeck/readeck/internal/assets"
"github.com/readeck/readeck/internal/auth/signin"
"github.com/readeck/readeck/internal/bookmarks"
"github.com/readeck/readeck/internal/cookbook"
"github.com/readeck/readeck/internal/dashboard"
"github.com/readeck/readeck/internal/profile"
"github.com/readeck/readeck/internal/server"
)
func init() {
rootCmd.AddCommand(serveCmd)
serveCmd.PersistentFlags().StringVarP(
&configs.Config.Server.Host, "host", "H",
configs.Config.Server.Host, "server host")
serveCmd.PersistentFlags().IntVarP(
&configs.Config.Server.Port, "port", "p",
configs.Config.Server.Port, "server host")
}
var serveCmd = &cobra.Command{
Use: "serve",
RunE: runServe,
}
func runServe(_ *cobra.Command, _ []string) error {
if !configs.Config.Main.DevMode && len(configs.Config.Server.AllowedHosts) == 0 {
return fmt.Errorf("The server.allowed_hosts setting is not set")
}
s := server.New(configs.Config.Server.Prefix)
// Init session store
if err := s.InitSession(); err != nil {
return err
}
// Static asserts
assets.SetupRoutes(s)
// Auth routes
signin.SetupRoutes(s)
// Dashboard routes
dashboard.SetupRoutes(s)
// Bookmark routes
// - /bookmarks/*
// - /bm/* (for bookmark media files)
bookmarks.SetupRoutes(s)
// User routes
profile.SetupRoutes(s)
// Admin routes
admin.SetupRoutes(s)
// Only in dev mode
if configs.Config.Main.DevMode {
// Cookbook routes
cookbook.SetupRoutes(s)
}
log.WithField("url", fmt.Sprintf("http://%s:%d%s",
configs.Config.Server.Host, configs.Config.Server.Port, s.BasePath),
).Info("Starting server")
return s.ListenAndServe()
}