6 files changed,
+26,
-56
+1,
-1
1@@ -65,7 +65,7 @@
2
3 # Compute by running: nix build .#rtw
4 # Then copy the hash from the error message
5- vendorHash = "sha256-TtKY67qnriW7OYTlDTNoJD1nvyVw2YVSM8davHK8Evs=";
6+ vendorHash = "sha256-EzV57oX4Wgvn1KITyoBwycE0pt3QMj6IpK+8v6ndczs=";
7
8 doCheck = false;
9
+2,
-0
1@@ -6,6 +6,8 @@ dist
2 .vinxi
3 app.config.timestamp_*.js
4
5+config.toml
6+
7 # Environment
8 .env
9 .env*.local
+1,
-1
1@@ -74,7 +74,7 @@ func NewApp(cfg *Config) (*App, error) {
2 router.Group(func(r *middleware.Router) {
3 r.Use(middleware.RequestLogger, middleware.RequestID, Session(userService, errorHandler, CreateAnonymousSessions(false)))
4 // user homepage
5- r.Handle("GET /u/{id}", pages.NewUserHomeHandler(userService, docService, errorHandler))
6+ r.Handle("GET /u/{id}", pages.NewUserHomeHandler(userService, docService, errorHandler, cfg.Protomaps.APIKey))
7 })
8
9 // Routes related to the trip editor that require anon or logged-in session
+13,
-5
1@@ -36,6 +36,10 @@ type Geocoder struct {
2 URL string `toml:"url" comment:"URL of Waldo geocoding API"`
3 }
4
5+type Protomaps struct {
6+ APIKey string `toml:"api-key,commented" comment:"Protomaps API key (see https://protomaps.com)"`
7+}
8+
9 type User struct {
10 Email string `toml:"email,commented"`
11 Handle string `toml:"handle,commented"`
12@@ -43,11 +47,12 @@ type User struct {
13 }
14
15 type Config struct {
16- Server Server `toml:"server"`
17- YSweet YSweet `toml:"ysweet"`
18- Routing Routing `toml:"routing" comment:"configuration for Graphhopper routing API (local or hosted)"`
19- Geocoder Geocoder `toml:"geocoder" comment:"configuration for a Waldo geocoder (see https://git.kilimanjaro.io/waldo)"`
20- SuperUsers []User `toml:"superusers,commented" comment:"users added with superuser permissions at app startup"`
21+ Server Server `toml:"server"`
22+ YSweet YSweet `toml:"ysweet"`
23+ Routing Routing `toml:"routing" comment:"configuration for Graphhopper routing API (local or hosted)"`
24+ Geocoder Geocoder `toml:"geocoder" comment:"configuration for a Waldo geocoder (see https://git.kilimanjaro.io/waldo)"`
25+ Protomaps Protomaps `toml:"protomaps,commented" comment:"configuration for Protomaps map tiles"`
26+ SuperUsers []User `toml:"superusers,commented" comment:"users added with superuser permissions at app startup"`
27 }
28
29 func (c *Config) Validate() error {
30@@ -114,6 +119,9 @@ func WriteInitConfig(w io.Writer) error {
31 Geocoder: Geocoder{
32 URL: "http://127.0.0.1:8999",
33 },
34+ Protomaps: Protomaps{
35+ APIKey: "<your-protomaps-api-key>",
36+ },
37 SuperUsers: []User{
38 {
39 Email: "[email protected]",
+0,
-37
1@@ -1,37 +0,0 @@
2-[server]
3-# host bind address
4-host = '127.0.0.1'
5-# listening port
6-port = 8080
7-# one of DEBUG, INFO, ERROR
8-loglevel = 'DEBUG'
9-# public URL of server
10-public-url = 'http://127.0.0.1:8080'
11-# base directory for server state (empty = current working directory, relative paths resolved against working directory)
12-data-dir = ''
13-
14-[protomaps]
15-api-key = '44608337582f97a2'
16-
17-[ysweet]
18-# URL of the upstream jamsocket/ysweet server to persist documents
19-url = 'http://127.0.0.1:9000'
20-
21-# configuration for Graphhopper routing API (local or hosted)
22-[routing]
23-# URL of Graphhopper-compatible routing API (e.g., https://graphhopper.com/api/1)
24-url = 'http://127.0.0.1:8989'
25-# authorization token
26-# token = '<enter-token-if-required>'
27-
28-# configuration for a Waldo geocoder (see https://git.kilimanjaro.io/waldo)
29-[geocoder]
30-# URL of Waldo geocoding API
31-url = 'http://127.0.0.1:8999'
32-
33-# users added with superuser permissions at app startup
34-# [[superusers]]
35-# email = '[email protected]'
36-# handle = 'bt'
37-# run 'echo <password> | rtw hash' to quickly compute the hashed password
38-# hashed-password = 'use rtw hash to get this value'
+9,
-12
1@@ -1,7 +1,6 @@
2 package pages
3
4 import (
5- _ "embed"
6 "log/slog"
7 "math"
8 "net/http"
9@@ -14,14 +13,15 @@ import (
10 "git.kilimanjaro.io/rtw/user"
11 )
12
13-func NewUserHomeHandler(userService *user.Service, docService *document.Service, errHandler *httperr.Handler) http.Handler {
14- return &userHome{us: userService, ds: docService, eh: errHandler}
15+func NewUserHomeHandler(userService *user.Service, docService *document.Service, errHandler *httperr.Handler, apiKey string) http.Handler {
16+ return &userHome{us: userService, ds: docService, eh: errHandler, apiKey: apiKey}
17 }
18
19 type userHome struct {
20- us *user.Service
21- ds *document.Service
22- eh *httperr.Handler
23+ us *user.Service
24+ ds *document.Service
25+ eh *httperr.Handler
26+ apiKey string
27 }
28
29 type UserHomeData struct {
30@@ -34,9 +34,6 @@ type UserHomeData struct {
31 IsLoggedInUser bool
32 }
33
34-//go:embed .protomaps_api_key
35-var APIKey string
36-
37 const styleURL string = "https://api.protomaps.com/styles/v5/white/en.json?key="
38
39 func (u userHome) ServeHTTP(w http.ResponseWriter, r *http.Request) {
40@@ -97,8 +94,8 @@ func (u userHome) ServeHTTP(w http.ResponseWriter, r *http.Request) {
41 u.eh.Handle(http.StatusInternalServerError, w, r)
42 return
43 }
44- if APIKey == "" {
45- l.Error("error MAPTILER_API_KEY not set")
46+ if u.apiKey == "" {
47+ l.Error("error protomaps api key not set")
48 u.eh.Handle(http.StatusInternalServerError, w, r)
49 return
50 }
51@@ -108,7 +105,7 @@ func (u userHome) ServeHTTP(w http.ResponseWriter, r *http.Request) {
52 }
53 data := UserHomeData{
54 User: user,
55- StyleURL: styleURL + APIKey,
56+ StyleURL: styleURL + u.apiKey,
57 DocumentIDs: docIDs,
58 Documents: docContents,
59 Waypoints: allWaypoints,