docs: server (#187)

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Daniel Roe 2021-06-08 22:57:15 +01:00 committed by GitHub
parent e2f5a3c9b0
commit 9164179b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 2 deletions

View File

@ -1 +1,36 @@
# API Routes # API Routes
Nuxt will automatically read in any files in the `~/server/api` directory to create API endpoints.
Each file should export a default function that handles api requests. It can return a promise or JSON data directly or use `res.end()`. API routes are powered by [h3](https://github.com/unjs/h3).
**Example:** Hello world
```js [server/api/hello.ts]
export default async (req, res) => 'Hello World'
```
See result on http://localhost:3000/api/hello
**Example:** An async function
```js [server/api/async.ts]
import express from 'express'
export default async (req, res) => {
await someAsyncFunction()
return {
someData: true
}
}
```
**Example:** Using NodeJS style
```js [server/api/node.ts]
export default async (req, res) => {
res.statusCode = 200
res.end('Works!')
}
```

View File

@ -1 +1,11 @@
# Server Middleware # Server Middleware
Nuxt will automatically read in any files in the `~/server/middleware` to create server middleware for your project. (These files will be run on every request, unliked [API routes](./api) that are mapped to their own routes.)
Each file should export a default function that will handle a request.
```js
export default async (req, res) => {
req.someValue = true
}
```

View File

@ -1 +0,0 @@
# Storage

View File

@ -1 +0,0 @@
# Nitro (advanced)