Skip to content

Commit 6ce299c

Browse files
Devinxi middleware (#1952)
Co-authored-by: Brendan Allan <brendonovich@outlook.com>
1 parent 7351586 commit 6ce299c

8 files changed

Lines changed: 344 additions & 264 deletions

File tree

examples/with-strict-csp/src/middleware.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ export default createMiddleware({
2020
// For more details, see: https://vite.dev/config/build-options.html#build-assetsinlinelimit
2121
const csp = `
2222
default-src 'self';
23-
script-src ${
24-
isProd
25-
? // Note: The `https:` and `'unsafe-inline'` directives do not reduce the effectiveness of the CSP.
26-
// They are only fallbacks for older browsers that don't support `'strict-dynamic'`.
27-
`'nonce-${nonce}' 'strict-dynamic' 'unsafe-eval' https: 'unsafe-inline'`
28-
: "'self' 'unsafe-inline' 'unsafe-eval' https: http:"
23+
script-src ${isProd
24+
? // Note: The `https:` and `'unsafe-inline'` directives do not reduce the effectiveness of the CSP.
25+
// They are only fallbacks for older browsers that don't support `'strict-dynamic'`.
26+
`'nonce-${nonce}' 'strict-dynamic' 'unsafe-eval' https: 'unsafe-inline'`
27+
: "'self' 'unsafe-inline' 'unsafe-eval' https: http:"
2928
};
3029
style-src ${isProd ? `'nonce-${nonce}'` : "'self' 'unsafe-inline'"};
3130
img-src 'self' data:;

examples/with-strict-csp/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"strict": true,
1212
"noEmit": true,
1313
"isolatedModules": true,
14+
"types": ["vite/client"],
1415
"paths": {
1516
"~/*": ["./src/*"]
1617
}

packages/start/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"types": "./dist/router.d.ts"
2929
},
3030
"./server/spa": "./dist/server/spa/index.jsx",
31-
"./client/spa": "./dist/client/spa/index.jsx"
31+
"./client/spa": "./dist/client/spa/index.jsx",
32+
"./middleware": "./dist/middleware/index.jsx"
3233
},
3334
"dependencies": {
3435
"@babel/core": "^7.28.3",
@@ -64,4 +65,4 @@
6465
"devDependencies": {
6566
"@types/babel__core": "^7.20.5"
6667
}
67-
}
68+
}

0 commit comments

Comments
 (0)