litestar-vite-plugin 0.14.0 → 0.15.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <html lang="en" class="dark">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
 
7
- <title>Litestar Vite</title>
7
+ <title>Litestar Vite Dev Server</title>
8
8
 
9
9
  <!-- Fonts -->
10
10
  <link
@@ -13,171 +13,165 @@
13
13
  />
14
14
 
15
15
  <script src="https://cdn.tailwindcss.com"></script>
16
+ <script>
17
+ tailwind.config = {
18
+ darkMode: 'class',
19
+ theme: {
20
+ extend: {
21
+ colors: {
22
+ litestar: {
23
+ primary: '#202235', // Dark Blue/Black
24
+ accent: '#EDB641', // Gold
25
+ 'accent-light': '#FFD480', // Light Gold
26
+ gray: '#DCDFE4', // Light Gray
27
+ success: '#00b648',
28
+ error: '#ff7b72',
29
+ }
30
+ },
31
+ fontFamily: {
32
+ sans: ['Nunito', 'sans-serif'],
33
+ },
34
+ animation: {
35
+ 'blob': 'blob 7s infinite',
36
+ },
37
+ keyframes: {
38
+ blob: {
39
+ '0%': { transform: 'translate(0px, 0px) scale(1)' },
40
+ '33%': { transform: 'translate(30px, -50px) scale(1.1)' },
41
+ '66%': { transform: 'translate(-20px, 20px) scale(0.9)' },
42
+ '100%': { transform: 'translate(0px, 0px) scale(1)' },
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ </script>
49
+ <style>
50
+ body {
51
+ background-color: #202235;
52
+ background-image: radial-gradient(#2a2d45 1px, transparent 1px);
53
+ background-size: 24px 24px;
54
+ }
55
+ </style>
16
56
  </head>
17
- <body class="antialiased">
18
- <div
19
- class="relative flex min-h-screen flex-col justify-center overflow-hidden bg-gray-100 text-gray-600 dark:text-gray-400 dark:bg-gray-900 py-6 sm:py-12"
20
- >
21
- <div
22
- class="relative bg-white dark:bg-gray-800 px-6 pt-10 pb-8 shadow-xl ring-1 ring-gray-900/5 sm:mx-auto sm:max-w-xl sm:rounded-lg sm:px-10"
23
- >
24
- <div class="mx-auto">
25
- <div class="flex items-center justify-center space-x-6">
26
- <a href="https://litestar.dev">
27
- <svg
28
- viewBox="0 52 410 250"
29
- xmlns="http://www.w3.org/2000/svg"
30
- class="h-16 w-auto"
31
- >
57
+ <body class="antialiased min-h-screen flex flex-col items-center justify-center text-litestar-gray selection:bg-litestar-accent selection:text-litestar-primary overflow-hidden">
58
+
59
+ <!-- Main Container -->
60
+ <div class="relative w-full max-w-2xl px-6 py-12">
61
+
62
+ <!-- Animated Background Blobs -->
63
+ <div class="absolute top-0 -left-4 w-72 h-72 bg-litestar-accent/10 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob"></div>
64
+ <div class="absolute top-0 -right-4 w-72 h-72 bg-purple-500/10 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-2000"></div>
65
+ <div class="absolute -bottom-8 left-20 w-72 h-72 bg-blue-500/10 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-4000"></div>
66
+
67
+ <!-- Card -->
68
+ <div class="relative bg-gray-900/60 backdrop-blur-lg border border-white/10 rounded-3xl shadow-2xl overflow-hidden">
69
+
70
+ <!-- Top Accent Line -->
71
+ <div class="h-1 w-full bg-gradient-to-r from-transparent via-litestar-accent to-transparent opacity-50"></div>
72
+
73
+ <div class="px-8 py-10 sm:px-12 sm:py-12">
74
+
75
+ <!-- Header / Logos -->
76
+ <div class="flex items-center justify-center space-x-8 mb-10">
77
+ <!-- Litestar Logo -->
78
+ <a href="https://litestar.dev" target="_blank" class="group transition-transform hover:scale-110 duration-300 relative">
79
+ <div class="absolute inset-0 bg-litestar-accent/20 blur-xl rounded-full opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
80
+ <svg viewBox="0 52 410 250" xmlns="http://www.w3.org/2000/svg" class="relative h-20 w-auto drop-shadow-lg">
32
81
  <defs>
33
82
  <clipPath id="9eb7762d41">
34
- <path
35
- d="M 15.933594 105 L 328 105 L 328 259 L 15.933594 259 Z M 15.933594 105 "
36
- clip-rule="nonzero"
37
- />
83
+ <path d="M 15.933594 105 L 328 105 L 328 259 L 15.933594 259 Z M 15.933594 105 " clip-rule="nonzero"/>
38
84
  </clipPath>
39
85
  <clipPath id="183d3cc178">
40
- <path
41
- d="M 142 78.769531 L 359.433594 78.769531 L 359.433594 296.269531 L 142 296.269531 Z M 142 78.769531 "
42
- clip-rule="nonzero"
43
- />
86
+ <path d="M 142 78.769531 L 359.433594 78.769531 L 359.433594 296.269531 L 142 296.269531 Z M 142 78.769531 " clip-rule="nonzero"/>
44
87
  </clipPath>
45
88
  </defs>
46
89
  <g clip-path="url(#9eb7762d41)">
47
- <path
48
- fill="#edb641"
49
- d="M 147.625 240.3125 C 161.5 233.984375 173.554688 227.011719 183.425781 220.550781 C 202.304688 208.203125 226.4375 185.242188 227.761719 183.410156 L 218.917969 177.503906 L 211.257812 172.386719 L 235.503906 171.441406 L 243.296875 171.136719 L 245.414062 163.640625 L 252.007812 140.304688 L 260.402344 163.054688 L 263.097656 170.363281 L 270.890625 170.058594 L 295.136719 169.113281 L 276.078125 184.117188 L 269.953125 188.9375 L 272.652344 196.25 L 281.046875 218.996094 L 260.871094 205.523438 L 254.390625 201.195312 L 248.265625 206.015625 L 229.207031 221.023438 L 232.480469 209.425781 L 235.796875 197.691406 L 236.207031 196.234375 C 213.003906 213.585938 180.546875 230.304688 161.140625 236.488281 C 156.6875 237.90625 152.183594 239.179688 147.625 240.3125 Z M 101.992188 258.078125 C 136.382812 256.734375 177.355469 248 217.675781 222.363281 L 209.90625 249.867188 L 254.910156 214.4375 L 302.539062 246.246094 L 282.71875 192.539062 L 327.71875 157.109375 L 270.46875 159.34375 L 250.648438 105.636719 L 235.085938 160.726562 L 177.835938 162.964844 L 210.980469 185.097656 C 189.164062 204.921875 134.445312 247.195312 61.957031 250.03125 C 47.300781 250.601562 31.914062 249.558594 15.933594 246.394531 C 15.933594 246.394531 52.011719 260.035156 101.992188 258.078125 "
50
- fill-opacity="1"
51
- fill-rule="nonzero"
52
- />
90
+ <path fill="#edb641" d="M 147.625 240.3125 C 161.5 233.984375 173.554688 227.011719 183.425781 220.550781 C 202.304688 208.203125 226.4375 185.242188 227.761719 183.410156 L 218.917969 177.503906 L 211.257812 172.386719 L 235.503906 171.441406 L 243.296875 171.136719 L 245.414062 163.640625 L 252.007812 140.304688 L 260.402344 163.054688 L 263.097656 170.363281 L 270.890625 170.058594 L 295.136719 169.113281 L 276.078125 184.117188 L 269.953125 188.9375 L 272.652344 196.25 L 281.046875 218.996094 L 260.871094 205.523438 L 254.390625 201.195312 L 248.265625 206.015625 L 229.207031 221.023438 L 232.480469 209.425781 L 235.796875 197.691406 L 236.207031 196.234375 C 213.003906 213.585938 180.546875 230.304688 161.140625 236.488281 C 156.6875 237.90625 152.183594 239.179688 147.625 240.3125 Z M 101.992188 258.078125 C 136.382812 256.734375 177.355469 248 217.675781 222.363281 L 209.90625 249.867188 L 254.910156 214.4375 L 302.539062 246.246094 L 282.71875 192.539062 L 327.71875 157.109375 L 270.46875 159.34375 L 250.648438 105.636719 L 235.085938 160.726562 L 177.835938 162.964844 L 210.980469 185.097656 C 189.164062 204.921875 134.445312 247.195312 61.957031 250.03125 C 47.300781 250.601562 31.914062 249.558594 15.933594 246.394531 C 15.933594 246.394531 52.011719 260.035156 101.992188 258.078125 " fill-opacity="1" fill-rule="nonzero"/>
53
91
  </g>
54
92
  <g clip-path="url(#183d3cc178)">
55
- <path
56
- fill="#edb641"
57
- d="M 250.789062 78.96875 C 190.78125 78.96875 142.140625 127.570312 142.140625 187.519531 C 142.140625 198.875 143.886719 209.816406 147.121094 220.101562 C 151.847656 217.75 156.363281 215.316406 160.660156 212.84375 C 158.394531 204.789062 157.183594 196.296875 157.183594 187.519531 C 157.183594 135.871094 199.089844 93.996094 250.789062 93.996094 C 302.484375 93.996094 344.390625 135.871094 344.390625 187.519531 C 344.390625 239.171875 302.484375 281.042969 250.789062 281.042969 C 222.75 281.042969 197.597656 268.722656 180.441406 249.210938 C 175.453125 251.152344 170.402344 252.917969 165.289062 254.511719 C 185.183594 279.816406 216.082031 296.070312 250.789062 296.070312 C 310.792969 296.070312 359.433594 247.472656 359.433594 187.519531 C 359.433594 127.570312 310.792969 78.96875 250.789062 78.96875 "
58
- fill-opacity="1"
59
- fill-rule="nonzero"
60
- />
93
+ <path fill="#edb641" d="M 250.789062 78.96875 C 190.78125 78.96875 142.140625 127.570312 142.140625 187.519531 C 142.140625 198.875 143.886719 209.816406 147.121094 220.101562 C 151.847656 217.75 156.363281 215.316406 160.660156 212.84375 C 158.394531 204.789062 157.183594 196.296875 157.183594 187.519531 C 157.183594 135.871094 199.089844 93.996094 250.789062 93.996094 C 302.484375 93.996094 344.390625 135.871094 344.390625 187.519531 C 344.390625 239.171875 302.484375 281.042969 250.789062 281.042969 C 222.75 281.042969 197.597656 268.722656 180.441406 249.210938 C 175.453125 251.152344 170.402344 252.917969 165.289062 254.511719 C 185.183594 279.816406 216.082031 296.070312 250.789062 296.070312 C 310.792969 296.070312 359.433594 247.472656 359.433594 187.519531 C 359.433594 127.570312 310.792969 78.96875 250.789062 78.96875 " fill-opacity="1" fill-rule="nonzero"/>
61
94
  </g>
62
- <path
63
- fill="#edb641"
64
- d="M 92.292969 173.023438 L 98.289062 191.460938 L 117.691406 191.460938 L 101.992188 202.855469 L 107.988281 221.292969 L 92.292969 209.898438 L 76.59375 221.292969 L 82.589844 202.855469 L 66.894531 191.460938 L 86.296875 191.460938 L 92.292969 173.023438 "
65
- fill-opacity="1"
66
- fill-rule="nonzero"
67
- />
68
- <path
69
- fill="#edb641"
70
- d="M 120.214844 112.25 L 125.390625 128.167969 L 142.140625 128.167969 L 128.589844 138 L 133.765625 153.917969 L 120.214844 144.082031 L 106.664062 153.917969 L 111.839844 138 L 98.289062 128.167969 L 115.039062 128.167969 L 120.214844 112.25 "
71
- fill-opacity="1"
72
- fill-rule="nonzero"
73
- />
74
- <path
75
- fill="#edb641"
76
- d="M 34.695312 209.136719 L 37.71875 218.421875 L 47.492188 218.421875 L 39.585938 224.160156 L 42.605469 233.449219 L 34.695312 227.707031 L 26.792969 233.449219 L 29.8125 224.160156 L 21.90625 218.421875 L 31.679688 218.421875 L 34.695312 209.136719 "
77
- fill-opacity="1"
78
- fill-rule="nonzero"
79
- />
95
+ <path fill="#edb641" d="M 92.292969 173.023438 L 98.289062 191.460938 L 117.691406 191.460938 L 101.992188 202.855469 L 107.988281 221.292969 L 92.292969 209.898438 L 76.59375 221.292969 L 82.589844 202.855469 L 66.894531 191.460938 L 86.296875 191.460938 L 92.292969 173.023438 " fill-opacity="1" fill-rule="nonzero"/>
96
+ <path fill="#edb641" d="M 120.214844 112.25 L 125.390625 128.167969 L 142.140625 128.167969 L 128.589844 138 L 133.765625 153.917969 L 120.214844 144.082031 L 106.664062 153.917969 L 111.839844 138 L 98.289062 128.167969 L 115.039062 128.167969 L 120.214844 112.25 " fill-opacity="1" fill-rule="nonzero"/>
97
+ <path fill="#edb641" d="M 34.695312 209.136719 L 37.71875 218.421875 L 47.492188 218.421875 L 39.585938 224.160156 L 42.605469 233.449219 L 34.695312 227.707031 L 26.792969 233.449219 L 29.8125 224.160156 L 21.90625 218.421875 L 31.679688 218.421875 L 34.695312 209.136719 " fill-opacity="1" fill-rule="nonzero"/>
80
98
  </svg>
81
99
  </a>
82
- <svg
83
- xmlns="http://www.w3.org/2000/svg"
84
- class="h-6 w-6 text-gray-500"
85
- fill="none"
86
- viewBox="0 0 24 24"
87
- stroke="currentColor"
88
- stroke-width="2"
89
- >
90
- <path
91
- stroke-linecap="round"
92
- stroke-linejoin="round"
93
- d="M12 4v16m8-8H4"
94
- />
95
- </svg>
96
- <a href="https://vitejs.dev">
97
- <svg
98
- viewBox="0 0 410 404"
99
- fill="none"
100
- xmlns="http://www.w3.org/2000/svg"
101
- class="h-16 w-auto"
102
- >
103
- <path
104
- d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z"
105
- fill="url(#paint0_linear)"
106
- />
107
- <path
108
- d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z"
109
- fill="url(#paint1_linear)"
110
- />
100
+
101
+ <!-- Connection Icon -->
102
+ <div class="flex items-center text-litestar-gray/30">
103
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
104
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4" />
105
+ </svg>
106
+ </div>
107
+
108
+ <!-- Vite Logo -->
109
+ <a href="https://vitejs.dev" target="_blank" class="group transition-transform hover:scale-110 duration-300 relative">
110
+ <div class="absolute inset-0 bg-purple-500/20 blur-xl rounded-full opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
111
+ <svg viewBox="0 0 410 404" class="relative h-16 w-auto drop-shadow-lg" fill="none" xmlns="http://www.w3.org/2000/svg">
112
+ <path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
113
+ <path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
111
114
  <defs>
112
- <linearGradient
113
- id="paint0_linear"
114
- x1="6.00017"
115
- y1="32.9999"
116
- x2="235"
117
- y2="344"
118
- gradientUnits="userSpaceOnUse"
119
- >
120
- <stop stop-color="#41D1FF" />
121
- <stop offset="1" stop-color="#BD34FE" />
115
+ <linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
116
+ <stop stop-color="#41D1FF"/>
117
+ <stop offset="1" stop-color="#BD34FE"/>
122
118
  </linearGradient>
123
- <linearGradient
124
- id="paint1_linear"
125
- x1="194.651"
126
- y1="8.81818"
127
- x2="236.076"
128
- y2="292.989"
129
- gradientUnits="userSpaceOnUse"
130
- >
131
- <stop stop-color="#FFEA83" />
132
- <stop
133
- offset="0.0833333"
134
- stop-color="#FFDD35"
135
- />
136
- <stop offset="1" stop-color="#FFA800" />
119
+ <linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
120
+ <stop stop-color="#FFEA83"/>
121
+ <stop offset="0.0833333" stop-color="#FFDD35"/>
122
+ <stop offset="1" stop-color="#FFA800"/>
137
123
  </linearGradient>
138
124
  </defs>
139
125
  </svg>
140
126
  </a>
141
127
  </div>
142
- <div class="divide-y divide-gray-300 dark:divide-gray-700">
143
- <div class="py-8 text-base leading-7">
144
- <p>
145
- This is the Vite development server that
146
- provides Hot Module Replacement for your
147
- Litestar application.
148
- </p>
149
- <p class="mt-6">
150
- To access your Litestar application, you will
151
- need to run a local development server.
152
- </p>
128
+
129
+ <!-- Content -->
130
+ <div class="relative text-center space-y-8">
131
+ <div>
132
+ <h1 class="text-4xl sm:text-5xl font-bold text-white tracking-tight mb-2">
133
+ Litestar <span class="text-transparent bg-clip-text bg-gradient-to-r from-litestar-accent to-litestar-accent-light">Vite</span>
134
+ </h1>
135
+ <p class="text-litestar-gray/60 text-lg font-medium">Frontend Development Server</p>
153
136
  </div>
154
- <div class="pt-8 text-base leading-7">
155
- <p>
156
- Your Litestar application's configured
157
- <code
158
- class="text-sm font-bold text-gray-900 dark:text-gray-100"
159
- >APP_URL</code
160
- >
161
- is:<br />
162
- <a
163
- href="{{ APP_URL }}"
164
- class="font-semibold text-red-500 hover:text-red-600"
165
- >{{ APP_URL }}</a
166
- >
167
- </p>
168
- <p class="mt-6">
169
- Want more information on Litestar's Vite
170
- integration?
137
+
138
+ <div class="p-6 rounded-2xl bg-white/5 border border-white/10 shadow-inner">
139
+ <div class="flex items-center justify-center space-x-3 mb-4">
140
+ <span class="relative flex h-3 w-3">
141
+ <span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-litestar-success opacity-75"></span>
142
+ <span class="relative inline-flex rounded-full h-3 w-3 bg-litestar-success"></span>
143
+ </span>
144
+ <span class="text-sm font-semibold text-litestar-success tracking-wide uppercase">Server Active</span>
145
+ </div>
146
+
147
+ <p class="text-litestar-gray leading-relaxed">
148
+ This server provides <strong class="text-white">Hot Module Replacement (HMR)</strong> for your assets.
149
+ To view your application, ensure your Litestar backend is running.
171
150
  </p>
172
- <p>
173
- <a
174
- href="https://litestar.dev/docs/vite"
175
- class="font-semibold text-red-500 hover:text-red-600"
176
- >Read the docs &rarr;</a
177
- >
151
+ </div>
152
+
153
+ <div class="space-y-2">
154
+ <p class="text-litestar-gray/80">
155
+ Your application is configured at:
178
156
  </p>
157
+ <div class="inline-block group">
158
+ <a href="{{ APP_URL }}" class="text-2xl font-mono font-bold text-litestar-accent group-hover:text-litestar-accent-light transition-colors">
159
+ {{ APP_URL }}
160
+ </a>
161
+ <div class="h-px w-full bg-litestar-accent/30 group-hover:bg-litestar-accent transition-colors mt-1"></div>
162
+ </div>
179
163
  </div>
180
164
  </div>
165
+
166
+ <!-- Footer -->
167
+ <div class="mt-12 pt-8 border-t border-white/10 flex justify-center">
168
+ <a href="https://litestar.dev/docs/vite" target="_blank" class="group inline-flex items-center px-5 py-2.5 rounded-full bg-white/5 hover:bg-white/10 border border-white/10 hover:border-litestar-accent/50 transition-all duration-300">
169
+ <span class="text-sm font-semibold text-litestar-gray group-hover:text-white transition-colors">Documentation</span>
170
+ <svg xmlns="http://www.w3.org/2000/svg" class="ml-2 h-4 w-4 text-litestar-accent group-hover:translate-x-1 transition-transform" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
171
+ <path stroke-linecap="round" stroke-linejoin="round" d="M14 5l7 7m0 0l-7 7m7-7H3" />
172
+ </svg>
173
+ </a>
174
+ </div>
181
175
  </div>
182
176
  </div>
183
177
  </div>
@@ -0,0 +1,76 @@
1
+ /**
2
+ * CSRF token utilities for Litestar applications.
3
+ *
4
+ * The CSRF token is injected into the page by Litestar in one of these ways:
5
+ * 1. window.__LITESTAR_CSRF__ (SPA mode)
6
+ * 2. <meta name="csrf-token" content="..."> (template mode)
7
+ * 3. Inertia shared props (Inertia mode)
8
+ *
9
+ * @module
10
+ */
11
+ declare global {
12
+ interface Window {
13
+ __LITESTAR_CSRF__?: string;
14
+ }
15
+ }
16
+ /**
17
+ * Get the CSRF token from the page.
18
+ *
19
+ * Checks multiple sources in order:
20
+ * 1. window.__LITESTAR_CSRF__ (injected by SPA handler)
21
+ * 2. <meta name="csrf-token"> element
22
+ * 3. Inertia page props (if Inertia is present)
23
+ *
24
+ * @returns The CSRF token or empty string if not found
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { getCsrfToken } from 'litestar-vite-plugin/helpers'
29
+ *
30
+ * fetch('/api/submit', {
31
+ * method: 'POST',
32
+ * headers: {
33
+ * 'X-CSRF-Token': getCsrfToken(),
34
+ * },
35
+ * body: JSON.stringify(data),
36
+ * })
37
+ * ```
38
+ */
39
+ export declare function getCsrfToken(): string;
40
+ /**
41
+ * Create headers object with CSRF token included.
42
+ *
43
+ * @param additionalHeaders - Additional headers to include
44
+ * @returns Headers object with X-CSRF-Token set
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { csrfHeaders } from 'litestar-vite-plugin/helpers'
49
+ *
50
+ * fetch('/api/submit', {
51
+ * method: 'POST',
52
+ * headers: csrfHeaders({ 'Content-Type': 'application/json' }),
53
+ * body: JSON.stringify(data),
54
+ * })
55
+ * ```
56
+ */
57
+ export declare function csrfHeaders(additionalHeaders?: Record<string, string>): Record<string, string>;
58
+ /**
59
+ * Create a fetch wrapper that automatically includes CSRF token.
60
+ *
61
+ * @param input - Request URL or Request object
62
+ * @param init - Request options
63
+ * @returns Fetch response promise
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { csrfFetch } from 'litestar-vite-plugin/helpers'
68
+ *
69
+ * // Automatically includes CSRF token
70
+ * csrfFetch('/api/submit', {
71
+ * method: 'POST',
72
+ * body: JSON.stringify(data),
73
+ * })
74
+ * ```
75
+ */
76
+ export declare function csrfFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * CSRF token utilities for Litestar applications.
3
+ *
4
+ * The CSRF token is injected into the page by Litestar in one of these ways:
5
+ * 1. window.__LITESTAR_CSRF__ (SPA mode)
6
+ * 2. <meta name="csrf-token" content="..."> (template mode)
7
+ * 3. Inertia shared props (Inertia mode)
8
+ *
9
+ * @module
10
+ */
11
+ /**
12
+ * Get the CSRF token from the page.
13
+ *
14
+ * Checks multiple sources in order:
15
+ * 1. window.__LITESTAR_CSRF__ (injected by SPA handler)
16
+ * 2. <meta name="csrf-token"> element
17
+ * 3. Inertia page props (if Inertia is present)
18
+ *
19
+ * @returns The CSRF token or empty string if not found
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { getCsrfToken } from 'litestar-vite-plugin/helpers'
24
+ *
25
+ * fetch('/api/submit', {
26
+ * method: 'POST',
27
+ * headers: {
28
+ * 'X-CSRF-Token': getCsrfToken(),
29
+ * },
30
+ * body: JSON.stringify(data),
31
+ * })
32
+ * ```
33
+ */
34
+ export function getCsrfToken() {
35
+ // Check window global (SPA mode)
36
+ if (typeof window !== "undefined" && window.__LITESTAR_CSRF__) {
37
+ return window.__LITESTAR_CSRF__;
38
+ }
39
+ // Check meta tag (template mode)
40
+ if (typeof document !== "undefined") {
41
+ const meta = document.querySelector('meta[name="csrf-token"]');
42
+ if (meta) {
43
+ return meta.getAttribute("content") || "";
44
+ }
45
+ }
46
+ // Check Inertia page props
47
+ if (typeof window !== "undefined") {
48
+ const win = window;
49
+ const inertiaPage = win.__INERTIA_PAGE__;
50
+ if (inertiaPage?.props) {
51
+ const props = inertiaPage.props;
52
+ if (typeof props.csrf_token === "string") {
53
+ return props.csrf_token;
54
+ }
55
+ }
56
+ }
57
+ return "";
58
+ }
59
+ /**
60
+ * Create headers object with CSRF token included.
61
+ *
62
+ * @param additionalHeaders - Additional headers to include
63
+ * @returns Headers object with X-CSRF-Token set
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { csrfHeaders } from 'litestar-vite-plugin/helpers'
68
+ *
69
+ * fetch('/api/submit', {
70
+ * method: 'POST',
71
+ * headers: csrfHeaders({ 'Content-Type': 'application/json' }),
72
+ * body: JSON.stringify(data),
73
+ * })
74
+ * ```
75
+ */
76
+ export function csrfHeaders(additionalHeaders = {}) {
77
+ const token = getCsrfToken();
78
+ return {
79
+ ...additionalHeaders,
80
+ ...(token ? { "X-CSRF-Token": token } : {}),
81
+ };
82
+ }
83
+ /**
84
+ * Create a fetch wrapper that automatically includes CSRF token.
85
+ *
86
+ * @param input - Request URL or Request object
87
+ * @param init - Request options
88
+ * @returns Fetch response promise
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * import { csrfFetch } from 'litestar-vite-plugin/helpers'
93
+ *
94
+ * // Automatically includes CSRF token
95
+ * csrfFetch('/api/submit', {
96
+ * method: 'POST',
97
+ * body: JSON.stringify(data),
98
+ * })
99
+ * ```
100
+ */
101
+ export function csrfFetch(input, init) {
102
+ const token = getCsrfToken();
103
+ if (!token) {
104
+ return fetch(input, init);
105
+ }
106
+ const headers = new Headers(init?.headers);
107
+ if (!headers.has("X-CSRF-Token")) {
108
+ headers.set("X-CSRF-Token", token);
109
+ }
110
+ return fetch(input, {
111
+ ...init,
112
+ headers,
113
+ });
114
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Litestar Vite Helpers
3
+ *
4
+ * Utilities for working with Litestar applications from the frontend.
5
+ * These helpers work in both SPA and template modes.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { route, getCsrfToken, csrfFetch } from 'litestar-vite-plugin/helpers'
10
+ *
11
+ * // Generate a URL for a named route
12
+ * const url = route('user:detail', { user_id: 123 })
13
+ *
14
+ * // Make a fetch request with CSRF token
15
+ * await csrfFetch('/api/submit', {
16
+ * method: 'POST',
17
+ * body: JSON.stringify(data),
18
+ * })
19
+ * ```
20
+ *
21
+ * @module
22
+ */
23
+ export { getCsrfToken, csrfHeaders, csrfFetch } from "./csrf.js";
24
+ export { route, getRoutes, toRoute, currentRoute, isRoute, isCurrentRoute, getRelativeUrlPath, type RouteDefinition, type RoutesMap, } from "./routes.js";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Litestar Vite Helpers
3
+ *
4
+ * Utilities for working with Litestar applications from the frontend.
5
+ * These helpers work in both SPA and template modes.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { route, getCsrfToken, csrfFetch } from 'litestar-vite-plugin/helpers'
10
+ *
11
+ * // Generate a URL for a named route
12
+ * const url = route('user:detail', { user_id: 123 })
13
+ *
14
+ * // Make a fetch request with CSRF token
15
+ * await csrfFetch('/api/submit', {
16
+ * method: 'POST',
17
+ * body: JSON.stringify(data),
18
+ * })
19
+ * ```
20
+ *
21
+ * @module
22
+ */
23
+ // CSRF utilities
24
+ export { getCsrfToken, csrfHeaders, csrfFetch } from "./csrf.js";
25
+ // Route utilities
26
+ export { route, getRoutes, toRoute, currentRoute, isRoute, isCurrentRoute, getRelativeUrlPath, } from "./routes.js";