1 parent 942ee06 commit 3d30accCopy full SHA for 3d30acc
1 file changed
src/middleware.ts
@@ -0,0 +1,19 @@
1
+import { defineMiddleware } from 'astro:middleware'
2
+
3
+export const onRequest = defineMiddleware(async (_context, next) => {
4
+ const response = await next()
5
+ const contentType = response.headers.get('content-type')
6
7
+ if (!contentType || !contentType.startsWith('text/html') || /charset=/i.test(contentType)) {
8
+ return response
9
+ }
10
11
+ const headers = new Headers(response.headers)
12
+ headers.set('content-type', `${contentType}; charset=utf-8`)
13
14
+ return new Response(response.body, {
15
+ status: response.status,
16
+ statusText: response.statusText,
17
+ headers,
18
+ })
19
+})
0 commit comments