Skip to content

Commit 724186f

Browse files
committed
docs: add usage and contributing
1 parent 2f12bd6 commit 724186f

File tree

6 files changed

+148
-127
lines changed

6 files changed

+148
-127
lines changed

docs/content/1.documentation/1.getting-started/3.headers.md

-59
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Usage
2+
3+
Learn how to use headers and middleware both globally and per route.
4+
5+
---
6+
7+
:ellipsis{right=0px width=75% blur=150px}
8+
9+
Nuxt Security by default registers a set of **global** Nuxt `routeRules` that will make your application more secure by default. Both headers and middleware can be easily configured and even disabled when needed.
10+
11+
::alert{type="info"}
12+
ℹ Read more about security headers [here](https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html#use-appropriate-security-headers).
13+
::
14+
15+
## Global configuration
16+
17+
To override default behavior for Nuxt Security globally, follow this pattern:
18+
19+
```ts
20+
export default defineNuxtConfig({
21+
security: {
22+
headers: {
23+
// certain header
24+
xXSSProtection: '1',
25+
},
26+
27+
// certain middleware
28+
rateLimiter: {
29+
// options
30+
}
31+
}
32+
})
33+
```
34+
35+
## Per route configuration
36+
37+
To enable per-route configuration, use the `routeRules` like following:
38+
39+
```ts
40+
export default defineNuxtConfig({
41+
routeRules: {
42+
'/custom-route': {
43+
headers: {
44+
// certain header
45+
'Cross-Origin-Embedder-Policy': 'require-corp'
46+
},
47+
48+
// certain middleware
49+
security: {
50+
rateLimiter: {
51+
// options
52+
}
53+
}
54+
}
55+
}
56+
})
57+
```
58+
59+
You can also use route roules in pages like following:
60+
61+
```vue
62+
<template>
63+
<div>Hello from page</div>
64+
</template>
65+
66+
<script setup lang="ts">
67+
defineRouteRules({
68+
headers: {
69+
'X-XSS-Protection': '1'
70+
},
71+
security: {
72+
rateLimiter: {
73+
tokensPerInterval: 3,
74+
interval: 60000,
75+
},
76+
}
77+
})
78+
</script>
79+
```
80+
81+
::alert{type="warning"}
82+
When using `routeRules`, make sure to:
83+
84+
1. use the proper HTTP Header names like `Cross-Origin-Embedder-Policy` instead of `crossOriginEmbedderPolicy` and to not set the headers inside `security`. These headers are handled by Nuxt and you can check more [here](https://nuxt.com/docs/guide/concepts/rendering#hybrid-rendering).
85+
2. add middleware inside of `security` in certain route rule. This is a custom NuxtSecurity addition that does not exists in core Nuxt.
86+
::
87+
88+
## Disabling functionality
89+
90+
To disable certain middleware or headers, follow this pattern:
91+
92+
```ts
93+
export default defineNuxtConfig({
94+
// global
95+
security: {
96+
headers: {
97+
// certain header
98+
contentSecurityPolicy: false
99+
},
100+
101+
// certain middleware
102+
rateLimiter: false
103+
},
104+
105+
// per route
106+
routeRules: {
107+
'/custom-route': {
108+
security: {
109+
rateLimiter: false
110+
}
111+
}
112+
}
113+
})
114+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Contributing
2+
3+
We can never thank you enough for your contributions. ❤️
4+
5+
---
6+
7+
:ellipsis{right=0px width=75% blur=150px}
8+
9+
::alert{type="info"}
10+
ℹ Read more about Nuxt contribution guide [here](https://nuxt.com/docs/community/contribution).
11+
::
12+
13+
## How to contribute?
14+
15+
- Clone [nuxt-security](https://github.com/Baroshem/nuxt-security) repository
16+
- Install dependencies using `yarn`
17+
- Run `yarn dev:prepare` to generate type stubs.
18+
19+
## Nuxt Security
20+
21+
- Use `yarn dev` to start the [playground](https://github.com/Baroshem/nuxt-security/tree/main/playground) in development mode.
22+
- Apply your changes
23+
- Add tests into the [test/](https://github.com/Baroshem/nuxt-security/tree/main/test) directory and run `yarn test` to make sure they pass.
24+
- Check the code style with `yarn lint`
25+
- Before creating a PR, make sure to run `yarn build` and that no errors are reported.
26+
27+
### Documentation
28+
29+
- Use `yarn dev:docs` to start the [documentation](https://github.com/Baroshem/nuxt-security/tree/main/docs) in development mode.
30+
- Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
31+
- Update the content of the documentation in the [docs/content/](https://github.com/Baroshem/nuxt-security/tree/main/docs/content) directory.

docs/content/1.documentation/1.getting-started/4.middleware.md

-67
This file was deleted.

docs/content/1.documentation/5.advanced/2.faq.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Find answers for difficult questions.
44

55
---
66

7+
:ellipsis{right=0px width=75% blur=150px}
8+
79
## Testing CORS configuration
810

911
In the default configuration for CORS in Nuxt Security module, only the request that is coming from your origin (the same host by default) will be accepted and others will be rejected.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"dev:generate": "nuxi generate playground",
4343
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
4444
"dev:preview": "nuxi preview playground",
45+
"dev:docs": "cd docs && yarn dev",
4546
"lint": "eslint --ext .js,.ts,.vue",
4647
"test": "vitest run --silent",
4748
"test:watch": "vitest watch",
48-
"docs": "cd docs && yarn dev",
4949
"stackblitz": "cd .stackblitz && yarn && yarn dev"
5050
},
5151
"dependencies": {

0 commit comments

Comments
 (0)