Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/site/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func main() {
// Production options: AnonymousAuthenticator (default — per-browser
// session group), explicit origin allowlist for the docs deploy
// targets. The handler package's Handler signature accepts opts so
// the e2e test-server (docs/e2e/patterns/main.go) can supply
// WithPermissiveOriginCheck for random-port test setups.
// the e2e test-server can run in dev mode (WithDevMode(true)), which
// relaxes the origin check for random-port test setups.
mux.Handle("/apps/ui-patterns/", http.StripPrefix("/apps/ui-patterns", patterns.Handler("/apps/ui-patterns",
livetemplate.WithAuthenticator(&livetemplate.AnonymousAuthenticator{}),
livetemplate.WithAllowedOrigins(allowedOrigins),
Expand Down
7 changes: 3 additions & 4 deletions examples/counter-basic/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
7 changes: 3 additions & 4 deletions examples/counter/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
7 changes: 3 additions & 4 deletions examples/live-dashboard/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
3 changes: 1 addition & 2 deletions examples/live-dashboard/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func TestMain(m *testing.M) {
// carries the metrics markup — no Chrome required, so it runs in -short.
func TestLiveDashboard_SmokeHTTP(t *testing.T) {
handler := livedashboard.Handler(
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
livetemplate.WithDevMode(true), // also relaxes the WS origin check
)
srv := httptest.NewServer(handler)
defer srv.Close()
Expand Down
7 changes: 3 additions & 4 deletions examples/login/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
4 changes: 2 additions & 2 deletions examples/login/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func extractTemplate() string {
// sees the request URL.
//
// Production callers (cmd/site) supply WithAllowedOrigins; test-server
// callers (docs/e2e/login) supply WithDevMode + WithPermissiveOriginCheck
// for random-port test setups.
// callers run in dev mode (WithDevMode(true)), which relaxes the origin
// check so random test ports work.
func Handler(mountPath string, opts ...livetemplate.Option) http.Handler {
if mountPath == "" {
mountPath = "/"
Expand Down
7 changes: 3 additions & 4 deletions examples/patterns/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
2 changes: 1 addition & 1 deletion examples/patterns/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var (
// Pass extra livetemplate.Options as opts — these are appended to
// every internal template construction. Production callers (cmd/site)
// supply WithAuthenticator + WithAllowedOrigins; test-server callers
// (docs/e2e/patterns/main.go) supply WithPermissiveOriginCheck so
// run in dev mode (WithDevMode(true)), which relaxes the origin check so
// random per-test ports work over the WS upgrade.
//
// Why options aren't hardcoded here: production wants strict origin
Expand Down
7 changes: 3 additions & 4 deletions examples/progressive-enhancement/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ func main() {

var baseOpts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
baseOpts = append(baseOpts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
baseOpts = append(baseOpts, livetemplate.WithDevMode(true))
} else {
baseOpts = append(baseOpts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
4 changes: 2 additions & 2 deletions examples/progressive-enhancement/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func extractTemplate() string {
// Handler returns the progressive-enhancement app as an http.Handler
// ready to mount. Production callers (cmd/site) supply
// WithAllowedOrigins (and optionally WithWebSocketDisabled for the
// Tier B mount). Test-server callers supply WithDevMode +
// WithPermissiveOriginCheck for random-port setups.
// Tier B mount). Test-server callers run in dev mode (WithDevMode(true)),
// which relaxes the origin check for random-port setups.
func Handler(opts ...livetemplate.Option) http.Handler {
controller := &TodoController{validate: validator.New()}
initialState := &TodoState{}
Expand Down
7 changes: 3 additions & 4 deletions examples/redacted-form/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
3 changes: 1 addition & 2 deletions examples/redacted-form/redacted_form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func startServer(t *testing.T, clientJS, clientCSS string) (int, func()) {

mux := http.NewServeMux()
mux.Handle("/", redactedform.LiveHandler(
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
livetemplate.WithDevMode(true), // also relaxes the WS origin check
))
mux.HandleFunc("/livetemplate-client.js", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
Expand Down
7 changes: 3 additions & 4 deletions examples/seat-picker/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
7 changes: 3 additions & 4 deletions examples/shared-notepad/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ func main() {
livetemplate.WithAuthenticator(notepad.NewDemoBasicAuth()),
}
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
7 changes: 3 additions & 4 deletions examples/todos/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ func main() {

var opts []livetemplate.Option
if *dev || os.Getenv("LVT_DEV_MODE") == "true" {
opts = append(opts,
livetemplate.WithDevMode(true),
livetemplate.WithPermissiveOriginCheck(),
)
// Dev mode also relaxes the WebSocket origin check (allows all
// origins), so localhost on any port works during development.
opts = append(opts, livetemplate.WithDevMode(true))
} else {
opts = append(opts, livetemplate.WithAllowedOrigins([]string{
"https://livetemplate.fly.dev",
Expand Down
4 changes: 2 additions & 2 deletions examples/todos/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func extractTemplate() string {
// hrefs that must resolve to the live mount prefix).
//
// Production callers (cmd/site) supply WithAllowedOrigins; test-server
// callers supply WithPermissiveOriginCheck + WithDevMode for random-port
// setups.
// callers run in dev mode (WithDevMode(true)), which relaxes the origin
// check for random-port setups.
//
// Calling Handler more than once returns the same first-call handler
// (handlerOnce); the package-level state (DB, template) is one-shot
Expand Down
Loading