34 lines
877 B
Markdown
34 lines
877 B
Markdown
![]() |
## The server/ folder is ideal for handling server-side logic, such as:
|
|||
|
|
|||
|
Database operations
|
|||
|
Authentication and authorization
|
|||
|
File uploads and processing
|
|||
|
Integration with third-party APIs
|
|||
|
|
|||
|
7. Accessing Environment Variables
|
|||
|
You can access environment variables in your server-side code using process.env or Nuxt 3’s runtime config.
|
|||
|
Example:
|
|||
|
ts
|
|||
|
Copy
|
|||
|
|
|||
|
export default defineEventHandler((event) => {
|
|||
|
const apiKey = process.env.API_KEY;
|
|||
|
return { apiKey };
|
|||
|
});
|
|||
|
|
|||
|
8. Server-Side Rendering (SSR) Support
|
|||
|
The server/ folder works seamlessly with Nuxt 3’s SSR capabilities. For example, you can fetch data from your API routes during SSR using useFetch or useAsyncData.
|
|||
|
Example:
|
|||
|
vue
|
|||
|
Copy
|
|||
|
|
|||
|
<!-- <script setup>
|
|||
|
const { data } = await useFetch('/api/hello');
|
|||
|
</script>
|
|||
|
|
|||
|
<template>
|
|||
|
<div>
|
|||
|
<h1>{{ data.message }}</h1>
|
|||
|
</div>
|
|||
|
</template> -->
|