Skip to content

Commit 293c404

Browse files
authored
Add strict CSP example (#1903)
1 parent 3400dfc commit 293c404

File tree

13 files changed

+413
-29
lines changed

13 files changed

+413
-29
lines changed

examples/pnpm-lock.yaml

Lines changed: 155 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
dist
2+
.wrangler
3+
.output
4+
.vercel
5+
.netlify
6+
.vinxi
7+
app.config.timestamp_*.js
8+
9+
# Environment
10+
.env
11+
.env*.local
12+
13+
# dependencies
14+
/node_modules
15+
16+
# IDEs and editors
17+
/.idea
18+
.project
19+
.classpath
20+
*.launch
21+
.settings/
22+
23+
# Temp
24+
gitignore
25+
26+
# System Files
27+
.DS_Store
28+
Thumbs.db

examples/with-strict-csp/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Content Security Policy with Nonce
2+
3+
This example demonstrates how to implement a strict Content Security Policy (CSP) with a nonce in a SolidStart application.
4+
5+
## How to Use
6+
7+
You can use the Solid CLI to bootstrap the example with one of the following commands based on your package manager preference:
8+
9+
**npm:**
10+
11+
```bash
12+
npm init solid@latest --solidstart --ts --template with-strict-csp my-app-with-strict-csp
13+
```
14+
15+
**pnpm:**
16+
17+
```bash
18+
pnpm create solid --solidstart --ts --template with-strict-csp my-app-with-strict-csp
19+
```
20+
21+
**yarn:**
22+
23+
```bash
24+
yarn create solid@latest --solidstart --ts --template with-strict-csp my-app-with-strict-csp
25+
```
26+
27+
**bun:**
28+
29+
```bash
30+
bun create solid@latest --solidstart --ts --template with-strict-csp my-app-with-strict-csp
31+
```
32+
33+
**deno:**
34+
35+
```bash
36+
deno init --npm solid@latest --solidstart --ts --template with-strict-csp my-app-with-strict-csp
37+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from "@solidjs/start/config";
2+
3+
export default defineConfig({
4+
middleware: "src/middleware.ts"
5+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "example-bare",
3+
"type": "module",
4+
"scripts": {
5+
"dev": "vinxi dev",
6+
"build": "vinxi build",
7+
"start": "vinxi start"
8+
},
9+
"dependencies": {
10+
"@solidjs/start": "^1.1.0",
11+
"solid-js": "^1.9.5",
12+
"vinxi": "^0.5.3"
13+
},
14+
"engines": {
15+
"node": ">=22"
16+
}
17+
}
664 Bytes
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
body {
2+
font-family: Gordita, Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
3+
}
4+
5+
a {
6+
margin-right: 1rem;
7+
}
8+
9+
main {
10+
text-align: center;
11+
padding: 1em;
12+
margin: 0 auto;
13+
}
14+
15+
h1 {
16+
color: #335d92;
17+
text-transform: uppercase;
18+
font-size: 4rem;
19+
font-weight: 100;
20+
line-height: 1.1;
21+
margin: 4rem auto;
22+
max-width: 14rem;
23+
}
24+
25+
p {
26+
max-width: 14rem;
27+
margin: 2rem auto;
28+
line-height: 1.35;
29+
}
30+
31+
@media (min-width: 480px) {
32+
h1 {
33+
max-width: none;
34+
}
35+
36+
p {
37+
max-width: none;
38+
}
39+
}
40+
41+
.increment {
42+
font-family: inherit;
43+
font-size: inherit;
44+
padding: 1em 2em;
45+
color: #335d92;
46+
background-color: rgba(68, 107, 158, 0.1);
47+
border-radius: 2em;
48+
border: 2px solid rgba(68, 107, 158, 0);
49+
outline: none;
50+
width: 200px;
51+
font-variant-numeric: tabular-nums;
52+
cursor: pointer;
53+
}
54+
55+
.increment:focus {
56+
border: 2px solid #335d92;
57+
}
58+
59+
.increment:active {
60+
background-color: rgba(68, 107, 158, 0.2);
61+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createSignal } from "solid-js";
2+
import "./app.css";
3+
4+
export default function App() {
5+
const [count, setCount] = createSignal(0);
6+
7+
return (
8+
<main>
9+
<h1>Hello world!</h1>
10+
<button class="increment" onClick={() => setCount(count() + 1)} type="button">
11+
Clicks: {count()}
12+
</button>
13+
<p>
14+
Visit{" "}
15+
<a href="https://start.solidjs.com" target="_blank">
16+
start.solidjs.com
17+
</a>{" "}
18+
to learn how to build SolidStart apps.
19+
</p>
20+
</main>
21+
);
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @refresh reload
2+
import { mount, StartClient } from "@solidjs/start/client";
3+
4+
mount(() => <StartClient />, document.getElementById("app")!);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @refresh reload
2+
import { createHandler, StartServer } from "@solidjs/start/server";
3+
4+
export default createHandler(
5+
() => (
6+
<StartServer
7+
document={({ assets, children, scripts }) => (
8+
<html lang="en">
9+
<head>
10+
<meta charset="utf-8" />
11+
<meta name="viewport" content="width=device-width, initial-scale=1" />
12+
<link rel="icon" href="/favicon.ico" />
13+
{assets}
14+
</head>
15+
<body>
16+
<div id="app">{children}</div>
17+
{scripts}
18+
</body>
19+
</html>
20+
)}
21+
/>
22+
),
23+
event => ({ nonce: event.locals.nonce })
24+
);

0 commit comments

Comments
 (0)