2019-05-18 18:06:10 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"geeks-accelerator/oss/saas-starter-kit/example-project/internal/mid"
|
|
|
|
"geeks-accelerator/oss/saas-starter-kit/example-project/internal/platform/auth"
|
|
|
|
"geeks-accelerator/oss/saas-starter-kit/example-project/internal/platform/db"
|
|
|
|
"geeks-accelerator/oss/saas-starter-kit/example-project/internal/platform/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
const baseLayoutTmpl = "base.tmpl"
|
|
|
|
|
|
|
|
// API returns a handler for a set of routes.
|
|
|
|
func APP(shutdown chan os.Signal, log *log.Logger, staticDir, templateDir string, masterDB *db.DB, authenticator *auth.Authenticator, renderer web.Renderer) http.Handler {
|
|
|
|
|
|
|
|
// Construct the web.App which holds all routes as well as common Middleware.
|
|
|
|
app := web.NewApp(shutdown, log, mid.Logger(log), mid.Errors(log), mid.Metrics(), mid.Panics())
|
|
|
|
|
|
|
|
// Register health check endpoint. This route is not authenticated.
|
|
|
|
check := Check{
|
2019-05-20 22:16:58 -05:00
|
|
|
MasterDB: masterDB,
|
2019-05-18 18:06:10 -04:00
|
|
|
Renderer: renderer,
|
|
|
|
}
|
|
|
|
app.Handle("GET", "/v1/health", check.Health)
|
|
|
|
|
|
|
|
// Register user management and authentication endpoints.
|
|
|
|
u := User{
|
2019-05-20 22:16:58 -05:00
|
|
|
MasterDB: masterDB,
|
2019-05-18 18:06:10 -04:00
|
|
|
Renderer: renderer,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This route is not authenticated
|
|
|
|
app.Handle("POST", "/users/login", u.Login)
|
|
|
|
app.Handle("GET", "/users/login", u.Login)
|
|
|
|
|
|
|
|
// Register root
|
|
|
|
r := Root{
|
2019-05-20 22:16:58 -05:00
|
|
|
MasterDB: masterDB,
|
2019-05-18 18:06:10 -04:00
|
|
|
Renderer: renderer,
|
|
|
|
}
|
|
|
|
// This route is not authenticated
|
|
|
|
app.Handle("GET", "/index.html", r.Index)
|
|
|
|
app.Handle("GET", "/", r.Index)
|
|
|
|
|
|
|
|
// Static file server
|
2019-05-20 22:16:58 -05:00
|
|
|
app.Handle("GET", "/*", web.Static(staticDir, ""))
|
2019-05-18 18:06:10 -04:00
|
|
|
|
|
|
|
return app
|
|
|
|
}
|