You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Open the project in Visual Studio Code or your preferred code editor.
@@ -128,7 +128,7 @@ Once GitHub Actions workflow is complete, you can select the URL link to open th
128
128
129
129
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.
130
130
131
-
1. Open the `app/page.tsx` file and add an operation that sets the value of a variable, which is computed server-side. Examples include fetching data or other server operations.
131
+
1. Open the `app/page.tsx` file and add an operation that sets the value of a server-side computed variable. Examples include fetching data or other server operations.
132
132
133
133
```ts
134
134
export default functionHome() {
@@ -157,7 +157,7 @@ To add server-rendered data in your Next.js project using the App Router, edit a
157
157
>[!NOTE]
158
158
>This example forces dynamic rendering of this component to demonstrate server-rendering of the server's current time. The App Router model of Next.js recommends caching individual data requests to optimize the performance of your Next.js app. Read more on [data fetching and caching in Next.js](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating).
159
159
160
-
1. Update the `Home` component in _app/pages.tsx_ to render the server-side data.
160
+
1. Update the `Home` component in _app/pages.tsx_ to render the server-side data.
161
161
162
162
```ts
163
163
import { unstable_noStore as noStore } from 'next/cache';
@@ -169,8 +169,7 @@ To add server-rendered data in your Next.js project using the App Router, edit a
This is a Next.js application hosted on Azure Static Web Apps with
173
-
hybrid rendering. The time on the server is <strong>{timeOnServer}</strong>.
172
+
This is a Next.js application hosted on Azure Static Web Apps with hybrid rendering. The time on the server is <strong>{timeOnServer}</strong>.
174
173
</div>
175
174
</main>
176
175
);
@@ -179,11 +178,12 @@ To add server-rendered data in your Next.js project using the App Router, edit a
179
178
180
179
## Adding an API route
181
180
182
-
In addition to Server Components, Next.js provides [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) you can use to create API routes to your Next.js application. These APIs can be fetched in [Client Components](https://nextjs.org/docs/app/building-your-application/rendering/client-components).
181
+
In addition to Server Components, Next.js provides [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) you can use to create API routes to your Next.js application. You can fetch these APIs in [Client Components](https://nextjs.org/docs/app/building-your-application/rendering/client-components).
183
182
184
183
Begin by adding an API route.
185
184
186
185
1. Create a new file at `app/api/currentTime/route.tsx`. This file holds the Route Handler for the new API endpoint.
186
+
187
187
1. Add a handler function to return data from the API.
188
188
189
189
```ts
@@ -246,8 +246,7 @@ This Client Component fetches the API with a `useEffect` React hook to render th
This is a Next.js application hosted on Azure Static Web Apps with
250
-
hybrid rendering. The time on the server is <strong>{timeOnServer}</strong>.
249
+
This is a Next.js application hosted on Azure Static Web Apps with hybrid rendering. The time on the server is <strong>{timeOnServer}</strong>.
251
250
</div>
252
251
<CurrentTimeFromAPI />
253
252
</main>
@@ -261,7 +260,7 @@ This Client Component fetches the API with a `useEffect` React hook to render th
261
260
262
261
## Configure the runtime version for Next.js
263
262
264
-
Certain Next.js versions require specific Node.js versions. To configure a specific Node version, you can set the 'engines' property of your `package.json` file to designate a version.
263
+
Certain Next.js versions require specific Node.js versions. To configure a specific Node version, you can set the `engines` property of your `package.json` file to designate a version.
265
264
266
265
```json
267
266
{
@@ -274,7 +273,7 @@ Certain Next.js versions require specific Node.js versions. To configure a speci
274
273
275
274
## Set environment variables for Next.js
276
275
277
-
Next.js uses environment variables at build time and at request time, to support both static page generation and dynamic page generation with server-side rendering. Therefore, set environment variables both within the build and deploy task, and in the _Environment variables_ of your Azure Static Web Apps resource.
276
+
Next.js uses environment variables at build time and at request time, to support both static page generation and dynamic page generation with server-side rendering. Therefore, set environment variables both within the build and deploy task, and in the _Environment variables_ of your Azure Static Web Apps resource.
278
277
279
278
```yml
280
279
...
@@ -327,7 +326,7 @@ Next, configure the `build` command in the `package.json` file in order to copy
327
326
328
327
## Configure routing and middleware for deployment
329
328
330
-
Your Next.js project can be configured to have custom handling of routes with redirects, rewrites, and middleware. These handlers are commonly used for authentication, personalization, routing, and internationalization. Custom handling affects the default routing of your Next.js site and the configuration must be compatible with hosting on Static Web Apps.
329
+
You can configure your Next.js project handle of routes with custom redirects, rewrites, and middleware. These handlers are commonly used for authentication, personalization, routing, and internationalization. Custom handling affects the default routing of your Next.js site and the configuration must be compatible with hosting on Static Web Apps.
331
330
332
331
Static Web Apps validates that your Next.js site is successfully deployed by adding a page to your site at build time. The page is named `public/.swa/health.html`, and Static Web Apps verifies the successful startup and deployment of your site by navigating to `/.swa/health.html` and verifying a successful response. Middleware and custom routing, which includes redirects and rewrites, can affect the access of the `/.swa/health.html` path, which can prevent Static Web Apps' deployment validation. To configure middleware and routing for a successful deployment to Static Web Apps, follow these steps:
333
332
@@ -345,7 +344,7 @@ Static Web Apps validates that your Next.js site is successfully deployed by add
345
344
}
346
345
```
347
346
348
-
1. Configure your redirects in`next.config.js` to exclude routes starting with `.swa`
347
+
1. Configure your redirects in`next.config.js` to exclude routes starting with `.swa`.
349
348
350
349
```js
351
350
module.exports = {
@@ -361,7 +360,7 @@ Static Web Apps validates that your Next.js site is successfully deployed by add
361
360
};
362
361
```
363
362
364
-
1. Configure your rewrite rules in`next.config.js` to exclude routes starting with `.swa`
363
+
1. Configure your rewrite rules in`next.config.js` to exclude routes starting with `.swa`.
Copy file name to clipboardExpand all lines: includes/static-web-apps/static-web-apps-nextjs-backends.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,21 @@ ms.date: 06/11/2024
6
6
ms.author: cshoe
7
7
---
8
8
9
-
A managed backed is automatically available for every hybrid Next.js deployment. However, you can fine tune performance and take more control of the backend by assigning a custom backend to your site. The following steps show you how to associate a custom backend to your site.
9
+
A managed backed is automatically available for every hybrid Next.js deployment in all plans. However, you can fine- tune performance and take more control of the backend by assigning a custom backend to your site. If you switch between a managed backend to a linked backend, your site experiences no downtime.
10
+
11
+
The following steps show you how to associate a custom backend to your Standard plan and above static web apps.
12
+
13
+
> [!NOTE]
14
+
> Linked backends are only available for sites using the Standard plan or above.
10
15
11
16
1. Go to your static web app in the Azure portal.
12
17
13
18
1. Select **Settings** and then **APIs** from the side menu.
14
19
15
-
1. Under the *Backend Resource Name*, select the link labeled **(managed)**.
16
-
17
20
1. Select **Configure linked backend**.
18
21
19
22
1. Either create a new App Service Plan or select an existing App Service Plan.
20
23
21
-
Your selected App Service Plan must use at least an **S1** SKU.
24
+
Your selected App Service Plan must use at least an **S1** SKU.
0 commit comments