Skip to content

Commit ade4ab6

Browse files
committed
fix examples auth and smoke paths
1 parent ab095e0 commit ade4ab6

10 files changed

Lines changed: 41 additions & 26 deletions

File tree

examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ is required by project-level compiler commands.
1818
| SSR and guards | `examples/auth-guard/` | `cd examples/auth-guard && make check && make routes && make build` |
1919
| One generated binary | `examples/embed/` | `go run ./cmd/gowdk build --out /tmp/gowdk-embed-build --app /tmp/gowdk-embed-app --bin /tmp/gowdk-embed-site examples/embed/site.page.gwdk` |
2020
| Contracts and realtime | `examples/contracts/` | `go run ./cmd/gowdk build --config examples/contracts/gowdk.config.go --out /tmp/gowdk-contracts-build --app /tmp/gowdk-contracts-app --bin /tmp/gowdk-contracts-site examples/contracts/patients.page.gwdk` |
21-
| CSS and Tailwind | `examples/css/`, `examples/tailwind/` | `go run ./cmd/gowdk build --config examples/css/gowdk.config.go --out /tmp/gowdk-css-build examples/css/styled.page.gwdk` |
21+
| CSS | `examples/css/` | `go run ./cmd/gowdk build --config examples/css/gowdk.config.go --out /tmp/gowdk-css-build examples/css/styled.page.gwdk` |
22+
| Tailwind | `examples/tailwind/` | `go run ./cmd/gowdk build --config examples/tailwind/gowdk.config.go --out /tmp/gowdk-tailwind-build examples/tailwind/site.page.gwdk` |
23+
| SEO | `examples/seo/` | `go run ./cmd/gowdk build --config examples/seo/gowdk.config.go --out /tmp/gowdk-seo-build examples/seo/*.gwdk` |
2224
| Component assets and WASM islands | `examples/components/` | `go run ./cmd/gowdk build --out /tmp/gowdk-wasm-island examples/components/wasm/*.gwdk` |
2325
| Full-stack vertical slice | `examples/flagship/` | `cd examples/flagship && make check && make routes && make build` |
2426

examples/flagship/Makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
ROOT := ../..
2-
CONFIG := examples/flagship/gowdk.config.go
3-
APP_DIR := examples/flagship/.gowdk/app
1+
CONFIG := gowdk.config.go
2+
APP_DIR := .gowdk/app
43
HOOK_FILE := $(APP_DIR)/gowdkapp/flagship_hooks.go
54

65
.PHONY: check routes build serve clean
76

87
check:
9-
cd $(ROOT) && go run ./cmd/gowdk check --config $(CONFIG)
8+
go run ../../cmd/gowdk check --config $(CONFIG)
109

1110
routes:
12-
cd $(ROOT) && go run ./cmd/gowdk routes --config $(CONFIG)
11+
go run ../../cmd/gowdk routes --config $(CONFIG)
1312

1413
$(HOOK_FILE): apphooks/flagship_hooks.go.txt
15-
mkdir -p $(ROOT)/$(APP_DIR)/gowdkapp
16-
cp apphooks/flagship_hooks.go.txt $(ROOT)/$(HOOK_FILE)
14+
mkdir -p $(APP_DIR)/gowdkapp
15+
cp apphooks/flagship_hooks.go.txt $(HOOK_FILE)
1716

1817
build: $(HOOK_FILE)
19-
cd $(ROOT) && go run ./cmd/gowdk build --config $(CONFIG) --target flagship
18+
go run ../../cmd/gowdk build --config $(CONFIG) --target flagship
2019

2120
serve: build
22-
GOWDK_CSRF_SECRET=development-flagship-csrf-secret-32b GOWDK_ADDR=127.0.0.1:8092 bin/flagship
21+
GOWDK_CSRF_SECRET=development-flagship-csrf-secret-32b GOWDK_FLAGSHIP_SECRET=development-flagship-session-secret-32b GOWDK_ADDR=127.0.0.1:8092 bin/flagship
2322

2423
clean:
2524
rm -rf .gowdk bin dist

examples/flagship/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Run from this directory:
1111
make check
1212
make routes
1313
make build
14-
GOWDK_CSRF_SECRET=development-flagship-csrf-secret-32b GOWDK_ADDR=127.0.0.1:8092 bin/flagship
14+
GOWDK_CSRF_SECRET=development-flagship-csrf-secret-32b \
15+
GOWDK_FLAGSHIP_SECRET=development-flagship-session-secret-32b \
16+
GOWDK_ADDR=127.0.0.1:8092 \
17+
bin/flagship
1518
```
1619

1720
Expected build outputs:
@@ -68,7 +71,8 @@ The main generated routes are:
6871

6972
Use `demo@example.com` and `demo-password`. Override them with
7073
`GOWDK_FLAGSHIP_EMAIL`, `GOWDK_FLAGSHIP_PASSWORD`, and
71-
`GOWDK_FLAGSHIP_SECRET`.
74+
`GOWDK_FLAGSHIP_SECRET`. `GOWDK_FLAGSHIP_SECRET` is required and signs the demo
75+
session cookie.
7276

7377
## Current Limitations
7478

examples/flagship/apphooks/flagship_hooks.go.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package gowdkapp
33
import (
44
"time"
55

6-
gowdkratelimit "github.com/cssbruno/gowdk/addons/ratelimit"
76
flagship "github.com/cssbruno/gowdk/examples/flagship/src/app"
87
gowdkguard "github.com/cssbruno/gowdk/runtime/guard"
8+
gowdkratelimit "github.com/cssbruno/gowdk/runtime/ratelimit"
99
)
1010

1111
func init() {

examples/flagship/gowdk.config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ var Config = gowdk.Config{
1414
Include: []string{"src/**/*.gwdk"},
1515
},
1616
Build: gowdk.BuildConfig{
17-
Output: "examples/flagship/dist",
17+
Output: "dist",
1818
Targets: []gowdk.BuildTargetConfig{
1919
{
2020
Name: "flagship",
21-
Output: "examples/flagship/dist",
22-
App: "examples/flagship/.gowdk/app",
23-
Binary: "examples/flagship/bin/flagship",
21+
Output: "dist",
22+
App: ".gowdk/app",
23+
Binary: "bin/flagship",
2424
},
2525
},
2626
},
2727
CSS: gowdk.CSSConfig{
28-
Include: []string{"examples/flagship/styles/**/*.css"},
28+
Include: []string{"styles/*.css"},
2929
Output: gowdk.CSSOutputConfig{
3030
Dir: "assets/gowdk",
3131
HrefPrefix: "/assets/gowdk",

examples/flagship/src/app/app.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424
const sessionCookie = "gowdk_flagship_session"
2525

2626
func Login(_ context.Context, values form.Values) (response.Response, error) {
27+
if len(sessionSecret()) == 0 {
28+
return response.RedirectTo("/?login=failed"), nil
29+
}
2730
email := strings.TrimSpace(values.First("email"))
2831
password := values.First("password")
2932
if !constantEqual(email, env("GOWDK_FLAGSHIP_EMAIL", "demo@example.com")) ||
@@ -127,6 +130,9 @@ var sessions = struct {
127130
}{Values: map[string]session{}}
128131

129132
func currentSession(request *http.Request) (session, bool) {
133+
if len(sessionSecret()) == 0 {
134+
return session{}, false
135+
}
130136
if request == nil {
131137
return session{}, false
132138
}
@@ -159,11 +165,15 @@ func sign(value string) string {
159165
}
160166

161167
func signature(value string) string {
162-
mac := hmac.New(sha256.New, []byte(env("GOWDK_FLAGSHIP_SECRET", "development-flagship-secret-change-me")))
168+
mac := hmac.New(sha256.New, sessionSecret())
163169
_, _ = mac.Write([]byte(value))
164170
return base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
165171
}
166172

173+
func sessionSecret() []byte {
174+
return []byte(strings.TrimSpace(os.Getenv("GOWDK_FLAGSHIP_SECRET")))
175+
}
176+
167177
func sessionDuration() time.Duration {
168178
return 12 * time.Hour
169179
}

examples/flagship/src/app/home.page.gwdk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ view {
5656
<h2>Session action</h2>
5757
<form class="stack-form" g:post={Login}>
5858
<label>Email <input name="email" type="email" required value="demo@example.com" /></label>
59-
<label>Password <input name="password" type="password" required minlength="8" value="demo-password" /></label>
59+
<label>Password <input name="password" type="password" required minlength="8" /></label>
6060
<button>Sign in</button>
6161
</form>
6262
</div>

examples/i18n/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This example shows the first localization slice:
44

55
- `gowdk.config.go` declares `Config.I18N` locales.
66
- `messages.go` keeps typed message keys and catalogs in normal Go.
7-
- `messages_test.go` checks the typed message references against each locale
8-
catalog, which is the current CI-friendly extraction/completeness path.
7+
- `messages_test.go` checks the required typed message keys against each locale
8+
catalog without hand-maintained source line metadata.
99
- `home.page.gwdk` calls a Go build helper that reads
1010
`gowdk.BuildParams.LocaleCode()`.
1111

examples/i18n/messages.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const (
1212
messageIntro messageKey = "intro"
1313
)
1414

15-
var homeMessageRefs = []gowdki18n.MessageReference[messageKey]{
16-
gowdki18n.Ref(messageTitle, "examples/i18n/home.page.gwdk", 14, 9),
17-
gowdki18n.Ref(messageIntro, "examples/i18n/home.page.gwdk", 15, 8),
15+
var homeRequiredMessages = []gowdki18n.MessageReference[messageKey]{
16+
gowdki18n.Key(messageTitle),
17+
gowdki18n.Key(messageIntro),
1818
}
1919

2020
type HomeCopy struct {

examples/i18n/messages_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package i18nexample
33
import "testing"
44

55
func TestHomeMessagesComplete(t *testing.T) {
6-
if report := homeMessages.Check(homeMessageRefs); !report.OK() {
6+
if report := homeMessages.Check(homeRequiredMessages); !report.OK() {
77
t.Fatalf("localized message catalogs are incomplete:\n%s", report.Error())
88
}
99
}

0 commit comments

Comments
 (0)