From b5951c1210978753a63178074e934fd9b419cc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 22 Feb 2023 17:00:47 +0100 Subject: [PATCH 1/3] 1 update by Nuxt Studio --- docs/content/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/content/index.md b/docs/content/index.md index c665e5be3b..ab39859648 100644 --- a/docs/content/index.md +++ b/docs/content/index.md @@ -33,28 +33,28 @@ Build and Deploy Universal JavaScript Servers, everywhere. #title Rapid Development #description - Zero config setup with hot module replacement + Zero config setup with hot module replacement. :: ::card{icon=😌} #title Multi-Provider #description - Deploy same codebase to any provider without extra config + Deploy sthe ame codebase to any [deployment provider](/deploy) without extra config. :: ::card{icon=💼} #title Portable and Compact #description - Say goodbye to node_modules + Say goodbye to `node_modules`, output size is less than 1MB. :: ::card{icon=📁} #title Filesystem Routing #description - Automatically registers Server and API routes + Automatically registers Server and API routes. :: ::card{icon=🤏} @@ -68,7 +68,7 @@ Build and Deploy Universal JavaScript Servers, everywhere. #title Code-Splitting #description - Async chunk loading for fast server startup time + Async chunk loading for fast server startup time and answer. :: ::card{icon=👕} From f0a92d00aa2a36a9af77922ca9506459e7dfa45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 22 Feb 2023 20:30:53 +0100 Subject: [PATCH 2/3] 2 updates by Nuxt Studio --- .../1.guide/1.introduction/0.getting-started.md | 4 ++-- docs/content/index.md | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/content/1.guide/1.introduction/0.getting-started.md b/docs/content/1.guide/1.introduction/0.getting-started.md index 1a5dfcdd9e..49689732f5 100644 --- a/docs/content/1.guide/1.introduction/0.getting-started.md +++ b/docs/content/1.guide/1.introduction/0.getting-started.md @@ -1,6 +1,6 @@ -# Getting Started +# Getting Started -Let's create a new Nitro app! +Let's create a new Nitro app in few steps. ## Play online diff --git a/docs/content/index.md b/docs/content/index.md index ab39859648..779f3f30d0 100644 --- a/docs/content/index.md +++ b/docs/content/index.md @@ -75,41 +75,41 @@ Build and Deploy Universal JavaScript Servers, everywhere. #title TypeScript #description - TypeScript support out of the box with few more goodies + TypeScript support out of the box with few more goodies. :: ::card{icon=💾} #title Storage Layer #description - Multi driver and platform-agnostic storage system + Multi driver and platform-agnostic storage system. :: ::card{icon=💰} #title Cache API #description - Powerful built-in caching API + Powerful built-in caching API. :: ::card{icon=🐱} #title Hackable #description - Built to be customized + Built to be customized. :: ::card{icon=✨} #title Auto Imports #description - Automatically import utilities for the lazy folks and a minimal codebase + Automatically import utilities for the lazy folks and a minimal codebase. :: ::card{icon=🏛️} #title Backward compatible #description - Best-effort compatibility for using legacy npm packages, CommonJS and mocking Node.js modules for workers + Best-effort compatibility for using legacy npm packages, CommonJS and mocking Node.js modules for workers. :: :: From 1f78364797160acee5313a6e8c4bae67e760a664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 23 Feb 2023 15:11:18 +0100 Subject: [PATCH 3/3] 2 updates by Nuxt Studio --- .../1.guide/1.introduction/3.routing.md | 49 ++++++++++++------- docs/content/index.md | 18 +++---- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/docs/content/1.guide/1.introduction/3.routing.md b/docs/content/1.guide/1.introduction/3.routing.md index d3bb22211f..6e0987eb29 100644 --- a/docs/content/1.guide/1.introduction/3.routing.md +++ b/docs/content/1.guide/1.introduction/3.routing.md @@ -1,50 +1,63 @@ -# Route Handling +--- +title: Routing +--- -Nitro supports file-based routing for your API routes. +# Filesystem Routing -Handler files inside `routes/` and `api/` directory will be automatically mapped to [unjs/h3](https://github.com/unjs/h3) routes. +Nitro supports file-based routing for your API routes. -**Note:** `api/` is a shortcut for `routes/api` as a common prefix. However, please note that some deployment providers use `api/` directory for their API format. You can simply use the `routes/api` or `srcDir` option to move everything under `src/` or `server/` directory. +Handler files inside `routes/` directory will be automatically mapped to [unjs/h3](https://github.com/unjs/h3) routes. ## Usage -Check out [h3 JSDocs](https://www.jsdocs.io/package/h3#package-index-functions) for all available utilities. - -## Examples +```md +routes/ + api/ + test.ts <-- /api/test + hello.ts <-- /hello +``` -**Example:** Simple API route +### Simple route ```ts // routes/test.ts export default eventHandler(() => 'Hello World!') ``` -**Example:** API route with params +### Route with params ```js // routes/hello/[name].ts export default eventHandler(event => `Hello ${event.context.params.name}!`) ``` -**Example:** API route with a specific HTTP request method (get, post, put, delete, options and so on) +### Specific request method -```js -// routes/user.get.ts -export default eventHandler(async event => { +API route with a specific HTTP request method (get, post, put, delete, options and so on). + +::code-group +```js [GET] +// routes/users/[id].get.ts +export default eventHandler(async (event) => { + const { id } = event.context.params + // TODO: fetch user by id return `User profile!` }) ``` -```js -// routes/user.post.ts +```js [POST] +// routes/users.post.ts export default eventHandler(async event => { const body = await readBody(event) - // TODO: Handle body and update user - return `User updated!` + // TODO: Handle body and add user + return { updated: true } }) ``` +:: + +Check out [h3 JSDocs](https://www.jsdocs.io/package/h3#package-index-functions) for all available utilities like `readBody`. -**Example:** Catch all page +### Catch all route ```js // routes/[...].ts diff --git a/docs/content/index.md b/docs/content/index.md index 779f3f30d0..65404e5fdc 100644 --- a/docs/content/index.md +++ b/docs/content/index.md @@ -25,7 +25,7 @@ snippet: ⚗️ Nitro #description -Build and Deploy Universal JavaScript Servers, everywhere. +Build and Deploy Universal JavaScript Servers, everywhere. :br The engine powering [Nuxt 3](https://nuxt.com) and open to anyone. :: ::card-grid @@ -33,14 +33,14 @@ Build and Deploy Universal JavaScript Servers, everywhere. #title Rapid Development #description - Zero config setup with hot module replacement. + Zero config setup with hot module replacement for server code. :: ::card{icon=😌} #title - Multi-Provider + Deploy Everywhere #description - Deploy sthe ame codebase to any [deployment provider](/deploy) without extra config. + Deploy the same codebase to any [deployment provider](/deploy) with no extra config. :: ::card{icon=💼} @@ -54,7 +54,7 @@ Build and Deploy Universal JavaScript Servers, everywhere. #title Filesystem Routing #description - Automatically registers Server and API routes. + [Automatically registers](/guide/introduction/routing) server and API routes. :: ::card{icon=🤏} @@ -96,20 +96,20 @@ Build and Deploy Universal JavaScript Servers, everywhere. #title Hackable #description - Built to be customized. + Built to be customized with the [plugins](/guide/advanced/plugins) hooks system. :: ::card{icon=✨} #title Auto Imports #description - Automatically import utilities for the lazy folks and a minimal codebase. + Automatically import utilities for a minimal and clean codebase. Only the used ones will be added to the final bundle. :: ::card{icon=🏛️} #title - Backward compatible + Backward Compatible #description - Best-effort compatibility for using legacy npm packages, CommonJS and mocking Node.js modules for workers. + So you can use legacy npm packages, CommonJS and mocking Node.js modules for workers. :: ::