mirror of
https://github.com/acaloiaro/garbagespeak.com
synced 2026-07-21 10:12:19 +00:00
Fix up CORS stuff
This commit is contained in:
parent
c983e1c23d
commit
afc096d1d1
5 changed files with 27 additions and 22 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
|
static/
|
||||||
.env
|
.env
|
||||||
.hugo_build.lock
|
.hugo_build.lock
|
||||||
build
|
build
|
||||||
|
|
@ -7,4 +8,4 @@ themes/ananke
|
||||||
bin/build
|
bin/build
|
||||||
bin/develop
|
bin/develop
|
||||||
resources/_gen/
|
resources/_gen/
|
||||||
static/htmx.js
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
|
|
||||||
HTMX_VERSION=1.9.2
|
HTMX_VERSION=1.9.2
|
||||||
|
|
||||||
|
mkdir -p static/img
|
||||||
|
|
||||||
curl -sL "https://unpkg.com/htmx.org@$HTMX_VERSION" > static/htmx.js
|
curl -sL "https://unpkg.com/htmx.org@$HTMX_VERSION" > static/htmx.js
|
||||||
curl -sL "https://unpkg.com/htmx.org/dist/ext/remove-me.js" > static/remove-me.js
|
curl -sL "https://unpkg.com/htmx.org/dist/ext/remove-me.js" > static/remove-me.js
|
||||||
echo '<script type="text/javascript" src="/htmx.js"></script>' >> layouts/partials/extended_head.html
|
curl -sL "https://htmx.org/img/bars.svg" > static/img/bars.svg
|
||||||
|
|
||||||
|
echo '<script type="text/javascript" src="/htmx.js"></script>' > layouts/partials/extended_head.html
|
||||||
echo '<script type="text/javascript" src="/remove-me.js"></script>' >> layouts/partials/extended_head.html
|
echo '<script type="text/javascript" src="/remove-me.js"></script>' >> layouts/partials/extended_head.html
|
||||||
|
echo "<meta name=\"htmx-config\" content='{\"withCredentials\": true}'>" >> layouts/partials/extended_head.html
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
---
|
---
|
||||||
title: Log in
|
title: Log in
|
||||||
---
|
---
|
||||||
|
|
||||||
{{< html.inline >}}
|
{{< html.inline >}}
|
||||||
<div class="auth-wrapper">
|
<div class="auth-wrapper">
|
||||||
<div class="auth-form">
|
<div class="auth-form">
|
||||||
<form hx-post="{{ .Site.Params.apiBaseUrl }}/users/login">
|
<form hx-post="{{ .Site.Params.apiBaseUrl }}/users/login">
|
||||||
<label for="username">Username</label>
|
<div hx-target="this" hx-swap="outerHTML">
|
||||||
<input id="username" type="text" name="username" placeholder="desired username"/>
|
<label for="username">Username</label>
|
||||||
|
<input id="username" type="text" name="username" placeholder="desired username" hx-post="{{ .Site.Params.apiBaseUrl }}/users/login">
|
||||||
<label for="password">Password</label>
|
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
||||||
<input id="password" type="password" name="password" placeholder="desired password">
|
<label for="password">Password</label>
|
||||||
|
<input id="password" type="password" name="password" placeholder="desired password">
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<button class="btn btn-success">Log In</button>
|
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<button class="btn btn-success">Log In</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
<meta name="htmx-config" content='{"withCredentials": true}'>
|
|
||||||
<script type="text/javascript" src="/htmx.js"></script>
|
<script type="text/javascript" src="/htmx.js"></script>
|
||||||
<script type="text/javascript" src="/remove-me.js"></script>
|
<script type="text/javascript" src="/remove-me.js"></script>
|
||||||
|
<meta name="htmx-config" content='{"withCredentials": true}'>
|
||||||
|
|
|
||||||
16
server.go
16
server.go
|
|
@ -113,11 +113,11 @@ func init() {
|
||||||
sessionStore = pgxstore.New(db)
|
sessionStore = pgxstore.New(db)
|
||||||
|
|
||||||
sessions.Cookie.Name = "session_id"
|
sessions.Cookie.Name = "session_id"
|
||||||
//sessions.Cookie.Domain = siteDomain()
|
sessions.Cookie.Domain = siteDomain()
|
||||||
//sessions.Cookie.HttpOnly = true
|
sessions.Cookie.HttpOnly = true
|
||||||
//sessions.Cookie.Persist = true
|
sessions.Cookie.Persist = true
|
||||||
sessions.Cookie.SameSite = http.SameSiteNoneMode
|
sessions.Cookie.SameSite = http.SameSiteNoneMode
|
||||||
//sessions.Cookie.Secure = true
|
sessions.Cookie.Secure = true
|
||||||
sessions.Store = sessionStore
|
sessions.Store = sessionStore
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
@ -144,7 +144,7 @@ func main() {
|
||||||
defer NQ.Shutdown(context.Background())
|
defer NQ.Shutdown(context.Background())
|
||||||
|
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
//r.Use(sessions.LoadAndSave)
|
r.Use(sessions.LoadAndSave)
|
||||||
r.Use(middleware.Logger)
|
r.Use(middleware.Logger)
|
||||||
r.Use(middleware.RequestID)
|
r.Use(middleware.RequestID)
|
||||||
r.Use(middleware.RealIP)
|
r.Use(middleware.RealIP)
|
||||||
|
|
@ -153,8 +153,8 @@ func main() {
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
AllowedOrigins: []string{"http://localhost:1313", fmt.Sprintf("https://%s", os.Getenv("SITE_DOMAIN"))},
|
AllowedOrigins: []string{"http://localhost:1313", fmt.Sprintf("https://%s", os.Getenv("SITE_DOMAIN"))},
|
||||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||||
AllowedHeaders: []string{"Accept", "Cookie", "Authorization", "Content-Type", "X-CSRF-Token", "hx-target", "hx-current-url", "hx-request"},
|
AllowedHeaders: []string{"Accept", "Cookie", "Authorization", "Content-Type", "X-CSRF-Token", "hx-target", "hx-current-url", "hx-request", "hx-trigger", "hx-trigger-name"},
|
||||||
ExposedHeaders: []string{"Link", "HX-Location"},
|
ExposedHeaders: []string{"Link", "HX-Location", "Vary", "Access-Control-Allow-Origin"},
|
||||||
MaxAge: 300, // Maximum value not ignored by any of major browsers
|
MaxAge: 300, // Maximum value not ignored by any of major browsers
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Printf("Starting API server on port 1314\n")
|
fmt.Printf("Starting API server on port 1314\n")
|
||||||
if err := http.ListenAndServe("0.0.0.0:1314", sessions.LoadAndSave(r)); err != nil {
|
if err := http.ListenAndServe("0.0.0.0:1314", r); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue