This is a practice space for working with the Nitro Server. It focuses on server/api
, but can also be used to practice with server/middleware
- Use the
server/api
folder to add SSR routes. - It also has fonts imported for example as well. see the devel branch
- Fork and Clone
- Use the main branch to create routes
- For examples from class, see the devel branch
- Try any of the following activities
- Use the documentation below for more ideas to practice
- For endpoints, use the
/server/api
directory
- Routing:
- Add more routes by creating multiple pages (put a title in each for easy recognition)
- In the nav component, create a computed property from the navLinks that returns all of the links except for
/pages/index.vue
- Create folders in pages with
index.vue
and 1 other route in each - Modify the pages that are shown to only show the root file of each folder
- Server:
- Create a route and make it print out 'Hello, Nitro' when you search to the route
localhost:3000/api/hello
- Create a route that return a bunch of json data
- Create a route that fetches data from a public api. Use
useAsyncData
oruseFetch
- Call information from your public api route onto one of your other pages (verify by checking the api endpoint and the rendered page)
- Create a route that returns a
new Date().toLocaleTimeString() of the current time. **then** fetch the data onto a page using
$fetch()` (see ohmyfetch doc linked below)
- Create a route and make it print out 'Hello, Nitro' when you search to the route
- Use a local JSON File to store data:
- Create a json file in your
public/data/
folder and add content to it (JSONplaceholder is a great place to get some, or write your own) - Then create an endpoint that imports the data and creates an endpoint for it
- Use
$fetch()
on a page to call the information and render it onto a page - Create separate endpoints for each item in your data. Example Syntax:
const {pathname } = new URL(req.url, `http://${req.headers.host}`) const id = pathname.split('/')[1]; if (!id) { return { posts } } else { return posts.find(post => post.id == parseInt(id)) }
- Then Create a dynamic page to generate pages for each post with
[id].vue
syntax
- Create a json file in your
- Storyblok:
- Connect storyblok to your project
- Add fetch content and render it on a page
- dynamically generate pages based on the pages that you've created in storyblok nuxt dynamic routes
- Configuration
- Use this doc for ideas of how to set up your configuration file
- Oh My Fetch: The module that gives us the
$fetch
syntax - Nuxt Documentation: Main Nuxt Doc Page
- Nuxt 3 Nitro Server: Documentation on the Server Engine
- Nuxt 3 Request Data
- H3 Server Documentation: H3 Minimal HTTP Framework
- Assets and Public Folders