Files
commerce/api/cdn/native/native.go
zeekay 1943f1c093 Hanzo Commerce
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
2026-09-23 21:52:16 -07:00

38 lines
851 B
Go

package native
import (
"os"
"strings"
"github.com/zap-proto/zip"
"github.com/hanzoai/commerce/config"
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/models/organization"
"github.com/hanzoai/commerce/util/fs"
"github.com/hanzoai/commerce/util/json/http"
)
var jsTemplate string
func Js(c *zip.Ctx) error {
db := datastore.New(c.Context())
id := c.Param("organizationid")
org := organization.New(db)
if err := org.GetById(id); err != nil {
return http.Fail(c, 400, "Failed to get organization", err)
}
if jsTemplate == "" {
var cwd, _ = os.Getwd()
jsTemplate = string(fs.ReadFile(cwd + "/js/native.js"))
}
c.SetHeader("Content-Type", "application/javascript")
script := strings.Replace(jsTemplate, "%%%%%url%%%%%", config.UrlFor("analytics", "/"+org.Id()+"/"), -1)
return c.String(200, script)
}