Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream-sync'
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa-nematpour committed Jan 21, 2025
2 parents 2cf405d + 8847d68 commit 67e7cde
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
9 changes: 9 additions & 0 deletions docs/config/preview-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ See [`server.host`](./server-options#server-host) for more details.

:::

## preview.allowedHosts

- **Type:** `string | true`
- **Default:** [`server.allowedHosts`](./server-options#server-allowedhosts)

The hostnames that Vite is allowed to respond to.

See [`server.allowedHosts`](./server-options#server-allowedhosts) for more details.

## preview.port

- **Type:** `number`
Expand Down
23 changes: 22 additions & 1 deletion docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ See [the WSL document](https://learn.microsoft.com/en-us/windows/wsl/networking#

:::

## server.allowedHosts

- **Type:** `string[] | true`
- **Default:** `[]`

The hostnames that Vite is allowed to respond to.
`localhost` and domains under `.localhost` and all IP addresses are allowed by default.
When using HTTPS, this check is skipped.

If a string starts with `.`, it will allow that hostname without the `.` and all subdomains under the hostname. For example, `.example.com` will allow `example.com`, `foo.example.com`, and `foo.bar.example.com`.

If set to `true`, the server is allowed to respond to requests for any hosts.
This is not recommended as it will be vulnerable to DNS rebinding attacks.

## server.port

- **Type:** `number`
Expand Down Expand Up @@ -147,8 +161,15 @@ export default defineConfig({
## server.cors

- **Type:** `boolean | CorsOptions`
- **Default:** `false`

Configure CORS for the dev server. Pass an [options object](https://github.com/expressjs/cors#configuration-options) to fine tune the behavior or `true` to allow any origin.

:::warning

Configure CORS for the dev server. This is enabled by default and allows any origin. Pass an [options object](https://github.com/expressjs/cors#configuration-options) to fine tune the behavior or `false` to disable.
We recommend setting a specific value rather than `true` to avoid exposing the source code to untrusted origins.

:::

## server.headers

Expand Down
5 changes: 5 additions & 0 deletions docs/guide/api-environment-frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ The `runner` is evaluated eagerly when it's accessed for the first time. Beware
Given a Vite server configured in middleware mode as described by the [SSR setup guide](/guide/ssr#setting-up-the-dev-server), let's implement the SSR middleware using the environment API. Error handling is omitted.

```js
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { createServer } from 'vite'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const server = await createServer({
server: { middlewareMode: true },
appType: 'custom',
Expand Down
6 changes: 6 additions & 0 deletions docs/guide/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ If you need a custom integration, you can follow the steps in this guide to conf
import { defineConfig } from 'vite'
// ---cut---
export default defineConfig({
server: {
cors: {
// the origin you will be accessing via browser
origin: 'http://my-backend.example.com',
},
},
build: {
// generate .vite/manifest.json in outDir
manifest: true,
Expand Down
15 changes: 12 additions & 3 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ During dev, simply navigate or link to `/nested/` - it works as expected, just l
During build, all you need to do is to specify multiple `.html` files as entry points:

```js twoslash [vite.config.js]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
build: {
rollupOptions: {
Expand All @@ -134,9 +137,12 @@ When it is time to bundle your library for distribution, use the [`build.lib` co
::: code-group
```js twoslash [vite.config.js (single entry)]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
build: {
lib: {
Expand All @@ -162,9 +168,12 @@ export default defineConfig({
```
```js twoslash [vite.config.js (multiple entries)]
import { resolve } from 'path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

const __dirname = dirname(fileURLToPath(import.meta.url))

export default defineConfig({
build: {
lib: {
Expand Down

0 comments on commit 67e7cde

Please sign in to comment.