Skip to content

Commit

Permalink
Change Vite config used for COI; update Vitest packages
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Jan 20, 2024
1 parent b34eb61 commit 40de155
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 164 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pnpm install sqlocal

### Cross-Origin Isolation

Since this package depends on the origin private file system API, the page you use it on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.
In order to persist data to the origin private file system, this package relies on APIs that require cross-origin isolation, so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.

```http
Cross-Origin-Embedder-Policy: require-corp
Expand All @@ -133,18 +133,12 @@ Cross-Origin-Opener-Policy: same-origin
If your development server uses Vite, you can do this by adding the following to your Vite configuration.

```javascript
plugins: [
{
name: 'configure-response-headers',
configureServer: (server) => {
server.middlewares.use((_req, res, next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
next();
});
},
server: {
headers: {
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
},
],
},
```

### Vite Configuration
Expand Down
20 changes: 7 additions & 13 deletions docs/guide/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pnpm install sqlocal

## Cross-Origin Isolation

Since this package depends on the origin private file system API, the page you use it on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.
In order to persist data to the origin private file system, this package relies on APIs that require cross-origin isolation, so the page you use this package on must be served with the following HTTP headers. Otherwise, the browser will block access to the origin private file system.

```http
Cross-Origin-Embedder-Policy: require-corp
Expand Down Expand Up @@ -65,19 +65,13 @@ optimizeDeps: {
},
```

To enable cross-origin isolation for the Vite development server, you can add this plug-in to your Vite configuration. Just don't forget to also configure your _production_ web server to use the same headers.
To enable cross-origin isolation (required for origin private file system persistence) for the Vite development server, you can add this to your Vite configuration. Just don't forget to also configure your _production_ web server to use the same HTTP headers.

```javascript
plugins: [
{
name: 'configure-response-headers',
configureServer: (server) => {
server.middlewares.use((_req, res, next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
next();
});
},
server: {
headers: {
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
},
],
},
```
Loading

0 comments on commit 40de155

Please sign in to comment.