-
-
-
diff --git a/docs/.docs/components/global/IconNitro.vue b/docs/.docs/components/global/IconNitro.vue
deleted file mode 100644
index 7cdb698f5c..0000000000
--- a/docs/.docs/components/global/IconNitro.vue
+++ /dev/null
@@ -1,3 +0,0 @@
-
- ⚗
-
diff --git a/docs/.docs/components/global/IconUnJS.vue b/docs/.docs/components/global/IconUnJS.vue
deleted file mode 100644
index 1a175cf96d..0000000000
--- a/docs/.docs/components/global/IconUnJS.vue
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
diff --git a/docs/.docs/components/global/Logo.vue b/docs/.docs/components/global/Logo.vue
deleted file mode 100644
index 8f5d59f58e..0000000000
--- a/docs/.docs/components/global/Logo.vue
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
diff --git a/docs/.docs/public/favicon.ico b/docs/.docs/public/favicon.ico
deleted file mode 100644
index 59886e68b8..0000000000
Binary files a/docs/.docs/public/favicon.ico and /dev/null differ
diff --git a/docs/.docs/public/icon.png b/docs/.docs/public/icon.png
deleted file mode 100644
index 190fa36848..0000000000
Binary files a/docs/.docs/public/icon.png and /dev/null differ
diff --git a/docs/.docs/public/nitro-dark.svg b/docs/.docs/public/nitro-dark.svg
deleted file mode 100644
index 28aea59c51..0000000000
--- a/docs/.docs/public/nitro-dark.svg
+++ /dev/null
@@ -1,38 +0,0 @@
-
diff --git a/docs/.docs/public/nitro-light.svg b/docs/.docs/public/nitro-light.svg
deleted file mode 100644
index 86f43f9b44..0000000000
--- a/docs/.docs/public/nitro-light.svg
+++ /dev/null
@@ -1,38 +0,0 @@
-
diff --git a/docs/1.guide/0.index.md b/docs/1.guide/0.index.md
index cfe762140d..06d135a522 100644
--- a/docs/1.guide/0.index.md
+++ b/docs/1.guide/0.index.md
@@ -72,7 +72,7 @@ The `routes/` directory contains your application handlers. You can create subdi
### `api/`
-The `api/` directory is similar to `routes/` with only difference that routes inside it will be prefixed with `/api/` for convenience.
+The `api/` directory is similar to `routes/` with the only difference that routes inside it will be prefixed with `/api/` for convenience.
:read-more{to="/guide/routing"}
diff --git a/docs/1.guide/1.utils.md b/docs/1.guide/1.utils.md
index 7a03f49c2f..e7fcbecd5b 100644
--- a/docs/1.guide/1.utils.md
+++ b/docs/1.guide/1.utils.md
@@ -58,8 +58,8 @@ Nitro also exposes several built-in utils:
- `nitroPlugin(plugin)`{lang=ts}
- `getRouteRules(event)`{lang=ts}
-::read-more{to="https://github.com/unjs/nitro/blob/main/src/imports.ts"}
-Check [the source code](https://github.com/unjs/nitro/blob/main/src/imports.ts) for list of available Nitro auto imports.
+::read-more{to="https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/imports.ts#L58"}
+Check [the source code](https://github.com/unjs/nitro/blob/v2/src/core/config/resolvers/imports.ts#L58) for list of available Nitro auto imports.
::
::read-more{to="/guide/typescript"}
diff --git a/docs/1.guide/10.tasks.md b/docs/1.guide/10.tasks.md
index 5ce12da6cf..a744ead52f 100644
--- a/docs/1.guide/10.tasks.md
+++ b/docs/1.guide/10.tasks.md
@@ -215,7 +215,7 @@ nitro task run db:migrate --payload "{}"
### Concurrency
-Each task can have **one running instance**. Calling a task of same name multiple times in parallel, results to calling it once and all callers will get the same return value.
+Each task can have **one running instance**. Calling a task of same name multiple times in parallel, results in calling it once and all callers will get the same return value.
> [!NOTE]
> Nitro tasks can be running multiple times and in parallel.
diff --git a/docs/1.guide/2.routing.md b/docs/1.guide/2.routing.md
index 74755f06d3..5adfbbe6e0 100644
--- a/docs/1.guide/2.routing.md
+++ b/docs/1.guide/2.routing.md
@@ -4,7 +4,7 @@ icon: ri:direction-line
# Server Routes
-> Nitro support filesystem routing to automatically map files to h3 routes.
+> Nitro supports filesystem routing to automatically map files to h3 routes.
## Event handlers
@@ -14,7 +14,7 @@ An [event handler](https://h3.unjs.io/guide/event-handler) is a function that wi
## Filesystem routing
-Nitro supports file-based routing for your API routes (file are automatically mapped to [h3 routes](https://h3.unjs.io/guide/router). Defining a route is as simple as creating a file inside the `api/` or `routes/` directory.
+Nitro supports file-based routing for your API routes (files are automatically mapped to [h3 routes](https://h3.unjs.io/guide/router)). Defining a route is as simple as creating a file inside the `api/` or `routes/` directory.
You can only define one handler per files and you can [append the HTTP method](#specific-request-method) to the filename to define a specific request method.
@@ -27,12 +27,26 @@ routes/
nitro.config.ts
```
+You can nest routes by creating subdirectories.
+
+```md
+routes/
+ communities/
+ index.get.ts
+ index.post.ts
+ [id]/
+ index.get.ts
+ index.post.ts
+ hello.get.ts
+ hello.post.ts
+```
+
::note
If you are using [Nuxt](https://nuxt.com), move the `server/api/` and `server/routes/` instead.
::
::tip
-Some providers like Vercel use a top-level `api/` directory as a feature, therefore routes placed in `/api` wont work.
+Some providers like Vercel use a top-level `api/` directory as a feature, therefore routes placed in `/api` won't work.
You will have to use `routes/api/`.
::
@@ -255,13 +269,21 @@ export default defineEventHandler((event) => {
})
```
+## Error handling
+
+You can use the [utilities available in H3](https://h3.unjs.io/guide/event-handler#error-handling) to handle errors in both routes and middlewares.
+
+The way errors are sent back to the client depends on the route's path. For most routes `Content-Type` is set to `text/html` by default and a simple html error page is delievered. If the route starts with `/api/` (either because it is placed in `api/` or `routes/api/`) the default will change to `application/json` and a JSON object will be sent.
+
+This behaviour can be overridden by some request properties (eg.: `Accept` or `User-Agent` headers).
+
## Route Rules
Nitro allows you to add logic at the top-level for each route of your configuration. It can be used for redirecting, proxying, caching and adding headers to routes.
It is a map from route pattern (following [unjs/radix3](https://github.com/unjs/radix3#route-matcher)) to route options.
-When `cache` option is set, handlers matching pattern will be automatically wrapped with `defineCachedEventHandler`. See the [guide cache](/guide/cache) to learn more about this function.
+When `cache` option is set, handlers matching pattern will be automatically wrapped with `defineCachedEventHandler`. See the [cache guide](/guide/cache) to learn more about this function.
::note
`swr: true|number` is shortcut for `cache: { swr: true, maxAge: number }`
diff --git a/docs/1.guide/3.websocket.md b/docs/1.guide/3.websocket.md
index 9e8eed1d6f..01d32359f1 100644
--- a/docs/1.guide/3.websocket.md
+++ b/docs/1.guide/3.websocket.md
@@ -4,7 +4,7 @@ icon: cib:socket-io
# WebSocket
-> Nitro natively support a cross platform WebSocket API
+> Nitro natively supports a cross platform WebSocket API
Nitro natively supports runtime agnostic [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) API using [CrossWS](https://crossws.unjs.io/) and [H3 WebSocket](https://h3.unjs.io/guide/websocket).
@@ -108,16 +108,16 @@ Create an SSE handler in `routes/sse.ts` (or `server/routes/sse.ts` for Nuxt).
```ts [sse.ts]
export default defineEventHandler(async (event) => {
const eventStream = createEventStream(event)
-
+
const interval = setInterval(async () => {
await eventStream.push(`Message @ ${new Date().toLocaleTimeString()}`)
}, 1000)
-
+
eventStream.onClosed(async () => {
clearInterval(interval)
await eventStream.close()
})
-
+
return eventStream.send()
})
```
@@ -126,7 +126,7 @@ Then connect to this SSE endpoint from the client
```ts
const eventSource = new EventSource('http://localhost:3000/sse')
-
+
eventSource.onmessage = (event) => {
console.log(event.data)
}
diff --git a/docs/1.guide/6.cache.md b/docs/1.guide/6.cache.md
index 825d6f99b6..2bf05f9a0d 100644
--- a/docs/1.guide/6.cache.md
+++ b/docs/1.guide/6.cache.md
@@ -59,7 +59,7 @@ export default defineEventHandler(async (event) => {
```
::
-The stars will be cached in development inside **.nitro/cache/functions/ghStars/<owner>/<repo>.json** with `value` being the number of stars.
+The stars will be cached in development inside ```.nitro/cache/functions/ghStars//.json``` with `value` being the number of stars.
```json
{"expires":1677851092249,"value":43991,"mtime":1677847492540,"integrity":"ZUHcsxCWEH"}
diff --git a/docs/2.deploy/10.runtimes/1.node.md b/docs/2.deploy/10.runtimes/1.node.md
index c782ec9e0c..475b4a0eae 100644
--- a/docs/2.deploy/10.runtimes/1.node.md
+++ b/docs/2.deploy/10.runtimes/1.node.md
@@ -42,7 +42,7 @@ You can customize server behavior using following environment variables:
**Preset:** `node_cluster`
-For more performance and leveraging multi core handling, you can use cluster preset.
+For more performance and leveraging multi-core handling, you can use cluster preset.
### Environment Variables
diff --git a/docs/2.deploy/20.providers/cloudflare.md b/docs/2.deploy/20.providers/cloudflare.md
index 5d5868daed..1f5aeb5087 100644
--- a/docs/2.deploy/20.providers/cloudflare.md
+++ b/docs/2.deploy/20.providers/cloudflare.md
@@ -26,21 +26,21 @@ If you use the [Cloudflare Pages GitHub/GitLab integration](https://developers.c
If instead you want preview your application locally and/or manually deploy it, when building the application you will need to let Nitro know that the target environment is the Cloudflare Pages one, you can do that in two ways:
-1. By defining either the `NITRO_PRESET` or the `SERVER_PRESET` environment variable set to `cloudflare_pages` when running the build process, like so:
+- By defining either the `NITRO_PRESET` or the `SERVER_PRESET` environment variable set to `cloudflare_pages` when running the build process, like so:
- ```bash
- NITRO_PRESET=cloudflare_pages npm run build
- ```
+ ```bash
+ NITRO_PRESET=cloudflare_pages npm run build
+ ```
-1. Or by updating your Nitro [preset configuration](/config#preset):
+- Or by updating your Nitro [preset configuration](/config#preset):
- ```json5
- "preset": "cloudflare_pages",
- ```
+ ```json5
+ "preset": "cloudflare_pages",
+ ```
-and then running the standard build command:
+ and then running the standard build command:
-:pm-run{script="build"}
+ :pm-run{script="build"}
### Wrangler
@@ -120,7 +120,7 @@ npm i wrangler
wrangler login
```
-Generate your app using the `cloudflare` preset:
+Generate your app using the `cloudflare_module` preset:
```bash
NITRO_PRESET=cloudflare_module npm run build
@@ -309,6 +309,6 @@ export default defineNuxtConfig({
From this moment, when running
-::pm-run{script="dev"}
+:pm-run{script="dev"}
you will be able to access the `MY_VARIABLE` and `MY_KV` from the request event just as illustrated above.
diff --git a/docs/2.deploy/20.providers/firebase.md b/docs/2.deploy/20.providers/firebase.md
index b9ff93f848..ecbc4f15fa 100644
--- a/docs/2.deploy/20.providers/firebase.md
+++ b/docs/2.deploy/20.providers/firebase.md
@@ -193,7 +193,7 @@ You can set custom Node.js version in configuration:
```ts [nitro.config.ts]
export default defineNitroConfig({
firebase: {
- nodeVersion: "18" // Can be "16" or "18" or "20"
+ nodeVersion: "20" // Can be "16", "18", "20" or "22"
},
});
```
@@ -202,7 +202,7 @@ export default defineNitroConfig({
export default defineNuxtConfig({
nitro: {
firebase: {
- nodeVersion: "18" // Can be "16" or "18" or "20"
+ nodeVersion: "20" // Can be "16", "18", "20" or "22"
},
},
});
@@ -218,7 +218,7 @@ You might also need to add a runtime key to your `firebase.json` file:
{
"functions": {
"source": ".output/server",
- "runtime": "nodejs18"
+ "runtime": "nodejs20"
}
}
```
@@ -263,3 +263,7 @@ export default defineNuxtConfig({
```
::
+
+::important
+`firebase.serverFunctionName` must be a valid JS variable name and cannot include dashes (`-`).
+::
diff --git a/docs/2.deploy/20.providers/genezio.md b/docs/2.deploy/20.providers/genezio.md
new file mode 100644
index 0000000000..8936d81d21
--- /dev/null
+++ b/docs/2.deploy/20.providers/genezio.md
@@ -0,0 +1,69 @@
+# Genezio
+
+> Deploy Nitro apps to Genezio.
+
+**Preset:** `genezio`
+
+:read-more{title="Genezio" to="https://genezio.com"}
+
+> [!NOTE]
+> This preset available via [nightly channel](https://nitro.unjs.io/guide/nightly) to try.
+
+
+## 1. Project Setup
+
+Create `genezio.yaml` file:
+
+```yaml
+# The name of the project.
+name: nitro-app
+# The version of the Genezio YAML configuration to parse.
+yamlVersion: 2
+backend:
+ # The root directory of the backend.
+ path: .output/
+ # Information about the backend's programming language.
+ language:
+ # The name of the programming language.
+ name: js
+ # The package manager used by the backend.
+ packageManager: npm
+ # Information about the backend's functions.
+ functions:
+ # The name (label) of the function.
+ - name: nitroServer
+ # The path to the function's code.
+ path: server/
+ # The name of the function handler
+ handler: handler
+ # The entry point for the function.
+ entry: index.mjs
+```
+
+::read-more{to="https://genezio.com/docs/project-structure/genezio-configuration-file/"}
+To further customize the file to your needs, you can consult the
+[official documentation](https://genezio.com/docs/project-structure/genezio-configuration-file/).
+::
+
+
+## 2. Deploy your project
+
+Build with the genezio nitro preset:
+
+```bash
+NITRO_PRESET=genezio npm run build
+```
+
+
+Deploy with [`genezio`](https://npmjs.com/package/genezio) cli:
+
+:pm-x{command="genezio deploy"}
+
+::read-more{title="Backend Environment Variables" to="https://genezio.com/docs/project-structure/backend-environment-variables"}
+To set environment viarables, please check out [Genezio - Environment Variables](https://genezio.com/docs/project-structure/backend-environment-variables).
+::
+
+
+## 3. Monitor your project
+You can monitor and manage your application through the [Genezio App Dashboard](https://app.genez.io/dashboard). The dashboard URL, also provided after deployment, allows you to access comprehensive views of your project's status and logs.
+
diff --git a/docs/2.deploy/20.providers/vercel.md b/docs/2.deploy/20.providers/vercel.md
index 4b1dc2e9b5..2371162bb0 100644
--- a/docs/2.deploy/20.providers/vercel.md
+++ b/docs/2.deploy/20.providers/vercel.md
@@ -145,3 +145,34 @@ To revalidate a page on demand:
::
3. To trigger "On-Demand Incremental Static Regeneration (ISR)" and revalidate a path to a Prerender Function, make a GET or HEAD request to that path with a header of x-prerender-revalidate: `bypassToken`. When that Prerender Function endpoint is accessed with this header set, the cache will be revalidated. The next request to that function should return a fresh response.
+
+### Fine-grained ISR config via route rules
+
+> [!IMPORTANT]
+> Fine-grained ISR config is currently possible by using the [nightly channel](https://nitro.unjs.io/guide/nightly).
+
+By default, query paramas are ignored by cache.
+
+You can pass an options object to `isr` route rule to configure caching behavior.
+
+- `expiration`: Expiration time (in seconds) before the cached asset will be re-generated by invoking the Serverless Function. Setting the value to `false` (or `isr: true` route rule) means it will never expire.
+- `group`: Group number of the asset. Prerender assets with the same group number will all be re-validated at the same time.
+- `allowQuery`: List of query string parameter names that will be cached independently.
+ - If an empty array, query values are not considered for caching.
+ - If `undefined` each unique query value is cached independently.
+ - For wildcard `/**` route rules, `url` is always added
+
+- `passQuery`: When `true`, the query string will be present on the `request` argument passed to the invoked function. The `allowQuery` filter still applies.
+
+```ts
+export default defineNitroConfig({
+ routeRules: {
+ "/products/**": {
+ isr: {
+ allowQuery: ["q"],
+ passQuery: true,
+ },
+ },
+ },
+});
+```
diff --git a/docs/2.deploy/20.providers/zerops.md b/docs/2.deploy/20.providers/zerops.md
new file mode 100644
index 0000000000..1898b59585
--- /dev/null
+++ b/docs/2.deploy/20.providers/zerops.md
@@ -0,0 +1,100 @@
+# Zerops
+
+> Deploy Nitro apps to [Zerops](https://zerops.io).
+
+**Preset:** `zerops`
+
+:read-more{title="zerops.io" to="https://zerops.io"}
+
+> [!NOTE]
+> This preset available via [nightly channel](https://nitro.unjs.io/guide/nightly) to try.
+
+Zerops supports deploying both static and server-side rendered apps with a simple configuration file in your project root.
+
+## Starter templates
+
+If you want to quckly get started with zerops and nitro you can use repositories [`zeropsio/recipe-nitro-nodejs`](https://github.com/zeropsio/recipe-nitro-nodejs) and [`zeropsio/recipe-nitro-static`](https://github.com/zeropsio/recipe-nitro-static) starter templates.
+
+## Project setup
+
+Projects and services can be added either through [project add wizard](https://app.zerops.io/dashboard/project-add) or imported using `zerops-project-import.yml`.
+
+::code-group
+```yml [zerops-project-import.yml (node.js)]
+project:
+ name: nitro-app
+
+services:
+ - hostname: app
+ type: nodejs@20
+```
+```yml [zerops-project-import.yml (static)]
+project:
+ name: nitro-app
+
+services:
+ - hostname: app
+ type: static
+```
+::
+
+Then create a `zerops.yml` config in your project root:
+
+::code-group
+```yml [zerops.yml (node.js)]
+zerops:
+ - setup: app
+ build:
+ base: nodejs@20
+ envVariables:
+ SERVER_PRESET: zerops
+ buildCommands:
+ - pnpm i
+ - pnpm run build
+ deployFiles:
+ - .output
+ - package.json
+ - node_modules
+ run:
+ base: nodejs@20
+ ports:
+ - port: 3000
+ httpSupport: true
+ start: node .output/server/index.mjs
+```
+```yml [zerops.yml (static)]
+zerops:
+ - setup: app
+ build:
+ base: nodejs@20
+ envVariables:
+ SERVER_PRESET: zerops-static
+ buildCommands:
+ - pnpm i
+ - pnpm build
+ deployFiles:
+ - .zerops/output/static/~
+ run:
+ base: static
+```
+::
+
+Now you can trigger the [build & deploy pipeline using the Zerops CLI](#building-deploying-your-app) or by connecting the app service with your [GitHub](https://docs.zerops.io/references/github-integration/) / [GitLab](https://docs.zerops.io/references/gitlab-integration) repository from inside the service detail.
+
+
+## Build and deploy
+
+Open [Settings > Access Token Management](https://app.zerops.io/settings/token-management) in the Zerops app and generate a new access token.
+
+Log in using your access token with the following command:
+
+:pm-x{command="@zerops/zcli login "}
+
+Navigate to the root of your app (where `zerops.yml` is located) and run the following command to trigger the deploy:
+
+:pm-x{command="@zerops/zcli push"}
+
+Your code can be deployed automatically on each commit or a new tag by connecting the service with your [GitHub](https://docs.zerops.io/references/gitlab-integration) / [GitLab](https://docs.zerops.io/references/gitlab-integration) repository. This connection can be set up in the service detail.
+
+
+:read-more{title="Zerops Documentation" to="https://docs.zerops.io/"}
diff --git a/docs/3.config/0.index.md b/docs/3.config/0.index.md
index 008507e31d..214397b5fb 100644
--- a/docs/3.config/0.index.md
+++ b/docs/3.config/0.index.md
@@ -20,7 +20,7 @@ The preset will automatically be detected when the `preset` option is not set an
- Default: `3`{lang=ts} (`1`{lang=ts} when the testing environment is detected)
-Log verbosity level. See [unjs/consola#level](https://github.com/unjs/consola/#level) for more information.
+Log verbosity level. See [unjs/consola](https://github.com/unjs/consola?tab=readme-ov-file#log-level) for more information.
### `runtimeConfig`
@@ -40,12 +40,12 @@ Enable experimental features.
#### `openAPI`
-Enable `/_nitro/scalar` and `/_nitro/swagger` and `/_nitro/openapi.json` endpoints.
-
-- Default: `false`
+Enable `/_nitro/scalar`, `/_nitro/swagger` and `/_nitro/openapi.json` endpoints.
> [!IMPORTANT]
-> [Scalar](https://scalar.com/) support is currently available in [nightly channel](/guide/nightly).
+> These endpoints are moving to `/_scalar`, `/_swagger` and `/_openapi.json` in [nightly channel](/guide/nightly) and [nitro v3](https://github.com/unjs/nitro/pull/2521).
+
+- Default: `false`
You can pass an object on the root level to modify your OpenAPI specification:
@@ -115,7 +115,7 @@ Path to main render (file should export an event handler as default)
Serve `public/` assets in production.
-**Note:** It is highly recommended that your edge CDN (nginx, apache, cloud) serves the `.output/public/` directory instead to enable compression and higher lever caching.
+**Note:** It is highly recommended that your edge CDN (Nginx, Apache, Cloud) serves the `.output/public/` directory instead of enabling compression and higher lever caching.
### `noPublicDir`
@@ -163,6 +163,7 @@ List of compressible MIME types:
- `application/json`
- `application/opentype`
- `application/otf`
+- `application/pdf`
- `application/pkcs7-mime`
- `application/protobuf`
- `application/rss+xml`
@@ -171,6 +172,7 @@ List of compressible MIME types:
- `application/vnd.apple.mpegurl`
- `application/vnd.mapbox-vector-tile`
- `application/vnd.ms-fontobject`
+- `application/wasm`
- `application/xhtml+xml`
- `application/xml`
- `application/x-font-opentype`
@@ -367,7 +369,7 @@ Default:
crawlLinks: false,
ignore: [],
routes: [],
- retries: 3,
+ retry: 3,
retryDelay: 500
}
```
diff --git a/docs/bun.lockb b/docs/bun.lockb
index d7ebfafe69..4a412a130a 100755
Binary files a/docs/bun.lockb and b/docs/bun.lockb differ
diff --git a/docs/package.json b/docs/package.json
index 0a537e2088..d6e253db5c 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -5,6 +5,6 @@
"build": "undocs build"
},
"devDependencies": {
- "undocs": "^0.2.21"
+ "undocs": "^0.2.29"
}
}
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 16d99b4a23..e550904702 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -8,5 +8,6 @@ export default unjs({
"@typescript-eslint/no-unused-vars": 0,
"unicorn/filename-case": 0,
"unicorn/consistent-function-scoping": 0,
+ "@typescript-eslint/no-empty-object-type": 0,
},
});
diff --git a/examples/api-routes/api/test.post.ts b/examples/api-routes/api/test.post.ts
index 710f745b69..04bdd4d4a9 100644
--- a/examples/api-routes/api/test.post.ts
+++ b/examples/api-routes/api/test.post.ts
@@ -1 +1,7 @@
-export default defineEventHandler(() => "Test post handler");
+export default defineEventHandler(async () => {
+ const body = await readBody(event);
+ return {
+ message: "Test post handler",
+ body,
+ };
+});
diff --git a/examples/api-routes/nitro.config.ts b/examples/api-routes/nitro.config.ts
index 2a9dd131e6..693fae5376 100644
--- a/examples/api-routes/nitro.config.ts
+++ b/examples/api-routes/nitro.config.ts
@@ -1 +1,3 @@
-export default defineNitroConfig({});
+export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
+});
diff --git a/examples/auto-imports/nitro.config.ts b/examples/auto-imports/nitro.config.ts
index 2a9dd131e6..693fae5376 100644
--- a/examples/auto-imports/nitro.config.ts
+++ b/examples/auto-imports/nitro.config.ts
@@ -1 +1,3 @@
-export default defineNitroConfig({});
+export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
+});
diff --git a/examples/cached-handler/nitro.config.ts b/examples/cached-handler/nitro.config.ts
index 2a9dd131e6..693fae5376 100644
--- a/examples/cached-handler/nitro.config.ts
+++ b/examples/cached-handler/nitro.config.ts
@@ -1 +1,3 @@
-export default defineNitroConfig({});
+export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
+});
diff --git a/examples/custom-error-handler/nitro.config.ts b/examples/custom-error-handler/nitro.config.ts
index 25ed9caae1..a42f717b5c 100644
--- a/examples/custom-error-handler/nitro.config.ts
+++ b/examples/custom-error-handler/nitro.config.ts
@@ -1,6 +1,7 @@
import errorHandler from "./error";
export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
errorHandler: "~/error",
devErrorHandler: errorHandler,
});
diff --git a/examples/database/nitro.config.ts b/examples/database/nitro.config.ts
index 55853ba2a3..a857aa19e7 100644
--- a/examples/database/nitro.config.ts
+++ b/examples/database/nitro.config.ts
@@ -1,4 +1,5 @@
export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
experimental: {
database: true,
tasks: true,
diff --git a/examples/graceful-shutdown/nitro.config.ts b/examples/graceful-shutdown/nitro.config.ts
index c19a01864d..35a05d1f45 100644
--- a/examples/graceful-shutdown/nitro.config.ts
+++ b/examples/graceful-shutdown/nitro.config.ts
@@ -1,3 +1,5 @@
import { defineNitroConfig } from "nitropack/config";
-export default defineNitroConfig({});
+export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
+});
diff --git a/examples/hello-world/nitro.config.ts b/examples/hello-world/nitro.config.ts
index 234d9ef730..bf73e94f58 100644
--- a/examples/hello-world/nitro.config.ts
+++ b/examples/hello-world/nitro.config.ts
@@ -1,4 +1,5 @@
// https://nitro.unjs.io/config
export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
srcDir: "server",
});
diff --git a/examples/middleware/nitro.config.ts b/examples/middleware/nitro.config.ts
index 2a9dd131e6..693fae5376 100644
--- a/examples/middleware/nitro.config.ts
+++ b/examples/middleware/nitro.config.ts
@@ -1 +1,3 @@
-export default defineNitroConfig({});
+export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
+});
diff --git a/examples/nano-jsx/nitro.config.ts b/examples/nano-jsx/nitro.config.ts
index 2a9dd131e6..693fae5376 100644
--- a/examples/nano-jsx/nitro.config.ts
+++ b/examples/nano-jsx/nitro.config.ts
@@ -1 +1,3 @@
-export default defineNitroConfig({});
+export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
+});
diff --git a/examples/plugins/nitro.config.ts b/examples/plugins/nitro.config.ts
index 1c68bd7097..7ac7cd5816 100644
--- a/examples/plugins/nitro.config.ts
+++ b/examples/plugins/nitro.config.ts
@@ -1,3 +1,4 @@
export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
plugins: ["~/plugins/test"],
});
diff --git a/examples/renderer/nitro.config.ts b/examples/renderer/nitro.config.ts
index 6ae31ab2f6..bc4234ee26 100644
--- a/examples/renderer/nitro.config.ts
+++ b/examples/renderer/nitro.config.ts
@@ -1,4 +1,4 @@
export default defineNitroConfig({
- compatibilityDate: "2024-06-21",
+ compatibilityDate: "2024-09-29",
renderer: "~/renderer",
});
diff --git a/examples/websocket/nitro.config.ts b/examples/websocket/nitro.config.ts
index dec37bc189..577c37eb5f 100644
--- a/examples/websocket/nitro.config.ts
+++ b/examples/websocket/nitro.config.ts
@@ -1,4 +1,5 @@
export default defineNitroConfig({
+ compatibilityDate: "2024-09-29",
experimental: {
websocket: true,
},
diff --git a/examples/websocket/routes/_ws.ts b/examples/websocket/routes/_ws.ts
index d86f1f2fe8..073e901f97 100644
--- a/examples/websocket/routes/_ws.ts
+++ b/examples/websocket/routes/_ws.ts
@@ -1,20 +1,22 @@
export default defineWebSocketHandler({
open(peer) {
- console.log("[ws] open", peer);
+ peer.send({ user: "server", message: `Welcome ${peer}!` });
+ peer.publish("chat", { user: "server", message: `${peer} joined!` });
+ peer.subscribe("chat");
},
-
message(peer, message) {
- console.log("[ws] message", peer, message);
if (message.text().includes("ping")) {
- peer.send("pong");
+ peer.send({ user: "server", message: "pong" });
+ } else {
+ const msg = {
+ user: peer.toString(),
+ message: message.toString(),
+ };
+ peer.send(msg); // echo
+ peer.publish("chat", msg);
}
},
-
- close(peer, event) {
- console.log("[ws] close", peer, event);
- },
-
- error(peer, error) {
- console.log("[ws] error", peer, error);
+ close(peer) {
+ peer.publish("chat", { user: "server", message: `${peer} left!` });
},
});
diff --git a/examples/websocket/routes/index.ts b/examples/websocket/routes/index.ts
index 012875eebe..1a5527963e 100644
--- a/examples/websocket/routes/index.ts
+++ b/examples/websocket/routes/index.ts
@@ -1,5 +1,191 @@
export default defineEventHandler(() => {
- return $fetch(
- "https://raw.githubusercontent.com/unjs/crossws/main/examples/h3/public/index.html"
- );
+ return /* html */ `
+
+
+ CrossWS Test Page
+
+
+
+
+
+
+
+