mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package default_
|
|
|
|
import (
|
|
nethttp "net/http"
|
|
|
|
"github.com/zap-proto/zip"
|
|
|
|
"github.com/hanzoai/commerce/config"
|
|
"github.com/hanzoai/commerce/log"
|
|
"github.com/hanzoai/commerce/middleware"
|
|
|
|
// "github.com/hanzoai/commerce/util/exec"
|
|
hashid "github.com/hanzoai/commerce/util/hashid/http"
|
|
"github.com/hanzoai/commerce/util/router"
|
|
"github.com/hanzoai/commerce/util/task"
|
|
"github.com/hanzoai/commerce/util/template"
|
|
|
|
// Imported for side-effect, ensures tasks are registered
|
|
_ "github.com/hanzoai/commerce/api/checkout/tasks"
|
|
_ "github.com/hanzoai/commerce/email/tasks"
|
|
_ "github.com/hanzoai/commerce/models/fixtures"
|
|
_ "github.com/hanzoai/commerce/models/referrer/tasks"
|
|
_ "github.com/hanzoai/commerce/models/webhook/tasks"
|
|
_ "github.com/hanzoai/commerce/util/aggregate/tasks"
|
|
// _ "github.com/hanzoai/commerce/thirdparty/salesforce/tasks"
|
|
)
|
|
|
|
func Init(app *zip.App) {
|
|
router := router.New(app, "default")
|
|
|
|
// Index, development has nice index with links
|
|
if config.IsDevelopment {
|
|
router.Raw(nethttp.MethodGet, "/", func(c *zip.Ctx) error {
|
|
return template.Render(c, "index.html")
|
|
})
|
|
} else {
|
|
router.Raw(nethttp.MethodGet, "/", func(c *zip.Ctx) error {
|
|
return c.String(200, "ok")
|
|
})
|
|
}
|
|
|
|
// Monitoring test
|
|
router.Raw(nethttp.MethodGet, "/wake-up", func(c *zip.Ctx) error {
|
|
log.Panic("I think I heard, I think I heard a shot.")
|
|
return nil
|
|
})
|
|
|
|
// Setup routes for tasks
|
|
task.SetupRoutes(router)
|
|
|
|
// Setup hashid routes
|
|
hashid.SetupRoutes(router)
|
|
|
|
// Development-only routes below
|
|
if config.IsProduction {
|
|
return
|
|
}
|
|
|
|
// Static assets
|
|
router.Raw(nethttp.MethodGet, "/static/*file", middleware.Static("static/"))
|
|
router.Raw(nethttp.MethodGet, "/assets/*file", middleware.Static("assets/"))
|
|
}
|