Skip to content

Commit

Permalink
added version prefix string; it's not possible to call this api via t…
Browse files Browse the repository at this point in the history
…he router without this
  • Loading branch information
Allan Degnan committed Feb 28, 2023
1 parent 851ea4a commit 8701e6a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func Setup(ctx context.Context, cfg *config.Config, r chi.Router, e EmailSender)
// and then mounts it to the existing router, in order to prevent existing endpoints (i.e. /health) to go through auth.
func (api *API) mountEndpoints(ctx context.Context) {
r := chi.NewRouter()
r.Route(api.Cfg.VersionPrefix, func(r chi.Router) {
r.Post("/feedback", api.PostFeedback)
})

r.Post("/feedback", api.PostFeedback)
api.Router.Mount("/", r)
}
Expand Down
5 changes: 3 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ func TestSetup(t *testing.T) {
r := chi.NewRouter()
ctx := context.Background()
cfg := &config.Config{
OnsDomain: "localhost",
OnsDomain: "localhost",
VersionPrefix: "/v1",
}
a := api.Setup(ctx, cfg, r, nil)

Convey("When created the following routes should have been added", func() {
So(hasRoute(a.Router, "/feedback", http.MethodPost), ShouldBeTrue)
So(hasRoute(a.Router, cfg.VersionPrefix+"/feedback", http.MethodPost), ShouldBeTrue)
})
})
}
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Config struct {
OnsDomain string `envconfig:"ONS_DOMAIN"`
FeedbackTo string `envconfig:"FEEDBACK_TO"`
FeedbackFrom string `envconfig:"FEEDBACK_FROM"`
VersionPrefix string `envconfig:"VERSION_PREFIX"`
Mail *Mail
Sanitize *Sanitize
}
Expand Down Expand Up @@ -49,6 +50,7 @@ func Get() (*Config, error) {
HealthCheckInterval: 30 * time.Second,
HealthCheckCriticalTimeout: 90 * time.Second,
OnsDomain: "localhost",
VersionPrefix: "/v1",
Mail: &Mail{
Host: "localhost",
Port: "1025",
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestConfig(t *testing.T) {
HealthCheckInterval: 30 * time.Second,
HealthCheckCriticalTimeout: 90 * time.Second,
OnsDomain: "localhost",
VersionPrefix: "/v1",
Mail: &Mail{
Host: "localhost",
Port: "1025",
Expand Down

0 comments on commit 8701e6a

Please sign in to comment.