Skip to content

Commit 320370b

Browse files
add nextjs server side rendering include
1 parent aab80e6 commit 320370b

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

articles/static-web-apps/deploy-nextjs-hybrid.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ Once GitHub Actions workflow is complete, you can select the URL link to open th
119119

120120
1. Open the project in Visual Studio Code or your preferred code editor.
121121

122+
## Set up server side rendering
123+
124+
[!INCLUDE [Server side rendering](../../includes/static-web-apps/static-web-apps-nextjs-backends.md)]
125+
122126
## Add Server-Rendered data with a Server Component
123127

124128
To add server-rendered data in your Next.js project using the App Router, edit a Next.js component to add a server-side operation to render data in the component. By default, Next.js components are [Server Components](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating) that can be server-rendered.
@@ -135,7 +139,7 @@ To add server-rendered data in your Next.js project using the App Router, edit a
135139
```
136140

137141
1. Import `unstable_noStore` from `next/cache` and call it within the `Home` component to ensure the route is dynamically rendered.
138-
142+
139143
```ts
140144
import { unstable_noStore as noStore } from 'next/cache';
141145
@@ -196,6 +200,7 @@ Begin by adding an API route.
196200
```
197201
198202
1. Create a new file at `app/components/CurrentTimeFromAPI.tsx`. This component creates a container for the Client Component that fetches the API from the browser.
203+
199204
1. Add a client component that fetches the API in this file.
200205
201206
```ts
@@ -248,7 +253,7 @@ This Client Component fetches the API with a `useEffect` React hook to render th
248253
);
249254
}
250255
```
251-
256+
252257
1. The result from the API route is displayed on the page.
253258
254259
:::image type="content" source="media/deploy-nextjs/nextjs-13-home-display.png" alt-text="Screenshot showing the display the output from the API route.":::
@@ -298,6 +303,7 @@ When your application size exceeds 250 MB, the Next.js [Output File Tracing](htt
298303
Output File Tracing creates a compressed version of the whole application with necessary package dependencies. This package is built into a folder named _.next/standalone_. With this package, your app can deploy on its own without _node_modules_ dependencies.
299304
300305
In order to enable the `standalone` feature, add the following property to your `next.config.js`:
306+
301307
```js
302308
module.exports ={
303309
output:"standalone",

articles/static-web-apps/nextjs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ With hybrid Next.js applications, pages and components can be dynamically render
2828

2929
Key features that are available in the preview are:
3030

31-
3231
- [App Router](https://nextjs.org/docs/app) and [Pages Router](https://nextjs.org/docs/pages)
3332
- [React Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components)
3433
- [Hybrid rendering](https://nextjs.org/docs/app/building-your-application/rendering/server-components#server-rendering-strategies)
@@ -42,6 +41,9 @@ Follow the [deploy hybrid Next.js applications](deploy-nextjs-hybrid.md) tutoria
4241

4342
[!INCLUDE [Unsupported Next.js features](../../includes/static-web-apps-nextjs-unsupported.md)]
4443

44+
## Server side rendering
45+
46+
[!INCLUDE [Server side rendering](../../includes/static-web-apps/static-web-apps-nextjs-backends.md)]
4547

4648
## Static HTML export
4749

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
author: craigshoemaker
3+
ms.service: static-web-apps
4+
ms.topic: include
5+
ms.date: 04/25/2024
6+
ms.author: cshoe
7+
---
8+
9+
Next.js applications that use server-side rendering require a dedicated Azure App Service as the deployment destination for the backend of the application. Once you have this hosting plan, you can link your static web app to the App Service plan.
10+
11+
When you link the backend resource to your Next.js app, server-side requests are served from the backend server.
12+
13+
Use the following steps to link your App Service plan to your static web app:
14+
15+
1. Create an Azure App Service under the **S1** plan.
16+
17+
1. Go to your static web app in the Azure portal.
18+
19+
1. In the *Settings* section, select **APIs**.
20+
21+
1. Append the following text to the end of the URL in your browser's location:
22+
23+
```text
24+
exp.AzurePortal_enable-nextjs=true
25+
```
26+
27+
Once you complete these steps, you can link your static web app to your App Service plan using this screen.

0 commit comments

Comments
 (0)