Support CSRF in HTMX non-form posts.
This commit is contained in:
parent
b2f64b62f4
commit
8860b981e6
3 changed files with 14 additions and 0 deletions
32
templates/components/core.gohtml
Normal file
32
templates/components/core.gohtml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{{define "metatags"}}
|
||||
<title>{{ .AppName }}{{ if .Title }} | {{ .Title }}{{ end }}</title>
|
||||
<link rel="icon" href="{{file "favicon.svg"}}">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
{{- if .Metatags.Description}}
|
||||
<meta name="description" content="{{.Metatags.Description}}">
|
||||
{{- end}}
|
||||
{{- if .Metatags.Keywords}}
|
||||
<meta name="keywords" content="{{.Metatags.Keywords | join ", "}}">
|
||||
{{- end}}
|
||||
{{end}}
|
||||
|
||||
{{define "css"}}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
|
||||
{{end}}
|
||||
|
||||
{{define "js"}}
|
||||
<script src="https://unpkg.com/htmx.org@1.6.1"></script>
|
||||
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
||||
{{end}}
|
||||
|
||||
{{define "footer"}}
|
||||
{{- if .CSRF}}
|
||||
<script>
|
||||
document.body.addEventListener('htmx:configRequest', (event) => {
|
||||
event.detail.parameters['csrf'] = '{{ .CSRF }}';
|
||||
})
|
||||
</script>
|
||||
{{end}}
|
||||
{{end}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue