mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
docs: add server-routes example (#4301)
This commit is contained in:
parent
f4fb9160c6
commit
25ced97f16
12
docs/content/4.examples/5.server/routes.md
Normal file
12
docs/content/4.examples/5.server/routes.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
template: Example
|
||||||
|
---
|
||||||
|
|
||||||
|
# Server Routes
|
||||||
|
|
||||||
|
This example shows how to create server routes inside a `server/api` directory.
|
||||||
|
|
||||||
|
::ReadMore{link="/guide/features/server-routes"}
|
||||||
|
::
|
||||||
|
|
||||||
|
::sandbox{repo="nuxt/framework" branch="main" dir="examples/server/routes" file="app.vue"}
|
9
examples/server/routes/app.vue
Normal file
9
examples/server/routes/app.vue
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<template>
|
||||||
|
<NuxtExampleLayout example="server/routes">
|
||||||
|
<p>Fetched from <pre>/api/mountain</pre>: {{ mountain }}</p>
|
||||||
|
</NuxtExampleLayout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
const { data: mountain } = await useFetch('/api/mountain')
|
||||||
|
</script>
|
7
examples/server/routes/nuxt.config.ts
Normal file
7
examples/server/routes/nuxt.config.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { defineNuxtConfig } from 'nuxt3'
|
||||||
|
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
modules: [
|
||||||
|
'@nuxt/ui'
|
||||||
|
]
|
||||||
|
})
|
13
examples/server/routes/package.json
Normal file
13
examples/server/routes/package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "example-server-routes",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "nuxi build",
|
||||||
|
"dev": "nuxi dev",
|
||||||
|
"start": "nuxi preview"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nuxt/ui": "npm:@nuxt/ui-edge@latest",
|
||||||
|
"nuxt3": "latest"
|
||||||
|
}
|
||||||
|
}
|
17
examples/server/routes/server/api/mountain.js
Normal file
17
examples/server/routes/server/api/mountain.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export default defineEventHandler(() => {
|
||||||
|
return {
|
||||||
|
title: 'Mount Everest',
|
||||||
|
description: "Mount Everest is Earth's highest mountain above sea level, located in the Mahalangur Himal sub-range of the Himalayas. The China–Nepal border runs across its summit point",
|
||||||
|
height: '8,848 m',
|
||||||
|
countries: [
|
||||||
|
'China',
|
||||||
|
'Nepal'
|
||||||
|
],
|
||||||
|
continent: 'Asia',
|
||||||
|
image: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Everest_kalapatthar.jpg/600px-Everest_kalapatthar.jpg',
|
||||||
|
dir: '/mountains',
|
||||||
|
path: '/mountains/mount-everest',
|
||||||
|
slug: 'mount-everest',
|
||||||
|
updatedAt: '2020-12-11T15:40:35.000Z'
|
||||||
|
}
|
||||||
|
})
|
3
examples/server/routes/tsconfig.json
Normal file
3
examples/server/routes/tsconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "./.nuxt/tsconfig.json"
|
||||||
|
}
|
@ -6514,6 +6514,15 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
"example-server-routes@workspace:examples/server/routes":
|
||||||
|
version: 0.0.0-use.local
|
||||||
|
resolution: "example-server-routes@workspace:examples/server/routes"
|
||||||
|
dependencies:
|
||||||
|
"@nuxt/ui": "npm:@nuxt/ui-edge@latest"
|
||||||
|
nuxt3: latest
|
||||||
|
languageName: unknown
|
||||||
|
linkType: soft
|
||||||
|
|
||||||
"example-teleport@workspace:examples/app/teleport":
|
"example-teleport@workspace:examples/app/teleport":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "example-teleport@workspace:examples/app/teleport"
|
resolution: "example-teleport@workspace:examples/app/teleport"
|
||||||
|
Loading…
Reference in New Issue
Block a user