Skip to content

Commit 6b9cfbc

Browse files
Reviews for deploy next and nuxt
1 parent 207b87d commit 6b9cfbc

File tree

2 files changed

+59
-66
lines changed

2 files changed

+59
-66
lines changed

articles/static-apps/deploy-nextjs.md

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Tutorial: Deploy server-rendered Next.js websites on App Service Static Apps"
3-
description: "Build with JAMstack: Generate and deploy Next.js dynamic sites with App Service Static App."
2+
title: "Tutorial: Deploy server-rendered Next.js websites on Azure Static Web Apps"
3+
description: "Generate and deploy Next.js dynamic sites with Azure Static Web Apps."
44
services: #Required for articles that deal with a service; service slug assigned to your service by ACOM.
55
author: christiannwamba
66
ms.service: azure-functions
@@ -12,17 +12,17 @@ ms.author: chnwamba
1212

1313
# Deploy server-rendered Next.js websites on App Service Static Apps
1414

15-
In this tutorial, you will learn how to deploy a [Next.js](https://nextjs.org) generated static website to [Azure App Service Static Apps](overview.md). You'll learn how to set up, configure, and deploy a Next.js app. You wil also learn how to deal with the most prominent challenges you might come across when generating static pages with Next.js
15+
In this tutorial, you learn to deploy a [Next.js](https://nextjs.org) generated static website to [Azure Static Web Apps](overview.md). To begin, you learn to set up, configure, and deploy a Next.js app. During this process, you also learn to deal with common challenges often faced when generating static pages with Next.js
1616

1717
## Prerequisites
1818

1919
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/).
2020
- A GitHub account. [Create an account for free](https://github.com/join).
2121
- [Node.js](https://nodejs.org) installed.
2222

23-
## Set up a Next.js App
23+
## Set up a Next.js app
2424

25-
You can set up a new Next.js project using `create-next-app`. Instead of a new project, let's clone a repository that is set up to demonstrate an edge case when you try to deploy a dynamic Next.js app. The repository contains an example of a dynamic site that we want to serve as a static site.
25+
Rather than using the Next.js CLI to create an app, you can use a starter repository that includes an existing Next.js app. This repository features a Next.js app with dynamic routes, which highlights a common deployment issue. Dynamic routes need an extra deployment configuration which you will learn more about in a moment.
2626

2727
1. Clone starter repository:
2828

@@ -58,9 +58,9 @@ When you click on a framework/library, you should see a details page about the s
5858

5959
## Generate a static website from Next.js build
6060

61-
When you build a Next.js site using `npm run build`, it only builds the app to be served like a regular web app, not a static site. Here is how to generate a static site from the build:
61+
When you build a Next.js site using `npm run build`, the app is built as a traditional web app, not a static site. To generate a static site, use the following application configuration.
6262

63-
1. Configure static routes--create a _next.config.js_ file at the root of your project and add the following route config:
63+
1. To configure static routes, create file named _next.config.js_ at the root of your project.
6464

6565
```javascript
6666
module.exports = {
@@ -73,9 +73,9 @@ When you build a Next.js site using `npm run build`, it only builds the app to b
7373
};
7474
```
7575
76-
This configuration will map `/` to the Next.js page that is served for `/`, and that is the _pages/index.js_ page file.
76+
This configuration maps `/` to the Next.js page that is served for the `/` route, and that is the _pages/index.js_ page file.
7777
78-
1. Update the _package.json_'s build script to also generate a static site after building, using the `next export` command:
78+
1. Update the _package.json_'s build script to also generate a static site after building, using the `next export` command. The `export` command generates a static site.
7979
8080
```json
8181
"scripts": {
@@ -84,22 +84,22 @@ When you build a Next.js site using `npm run build`, it only builds the app to b
8484
},
8585
```
8686
87-
App Service Static Apps will run the `build` script every time you push a commit.
87+
Now with this command in place, Static Web Apps will run the `build` script every time you push a commit.
8888
8989
1. Generate a static site:
9090
9191
```bash
9292
npm run build
9393
```
9494
95-
The static site will be generated and copied into an _out_ folder at the root of your working directory.
95+
The static site is generated and copied into an _out_ folder at the root of your working directory.
9696
9797
> [!NOTE]
98-
> This folder is ignored in _.gitignore_ because it should be generated by CI/CD when you deploy.
98+
> This folder is listed in the _.gitignore_ file because it should be generated by CI/CD when you deploy.
9999
100100
## Push your static website to GitHub
101101
102-
App Service Static Apps will deploy your app from a GitHub repository and it will keep doing so for every pushed commit. Set up a repository:
102+
Azure Static Web Apps deploys your app from a GitHub repository and keeps doing so for every pushed commit to a designated branch. Use the following command to set up a repository.
103103
104104
1. Initialize a git repo
105105
@@ -130,37 +130,37 @@ App Service Static Apps will deploy your app from a GitHub repository and it wil
130130
131131
## Deploy your static website
132132
133-
The following steps show how to create a new static site app and deploy it to a production environment.
133+
The following steps show how to deploy the app you just pushed to GitHub to Azure Static Web Apps. Once in Azure you can deploy the application to a production environment.
134134
135135
### Create Azure App Service Static App
136136
137137
1. Navigate to the [Azure Portal](https://portal.azure.com).
138-
1. Click **Create a Resource** then search for **Static App** and select it.
138+
1. Click **Create a Resource** then search for **Static Web Apps** and select the matching result.
139139
140140
[Image of Static App]
141141
142142
1. Select a subscription from the *Subscription* dropdown list or use the default one.
143143
1. Click the **New** link below the *Resource group* dropdown. In *New resource group name*, type **nextjsstaticsite** and click **OK**
144-
1. Provide a globally unique name for your app in the **Name** text box. Valid characters include `a-z`, `A-Z`, `0-9`, and `-`. This value is used as the URL prefix for your static app in the format of `https://<APP_NAME>.....`
145-
1. In the *Region* dropdown, choose a region closest to you.
146-
1. Select **Basic** from the SKU dropdown.
144+
1. Provide a globally unique name for your app in the **Name** text box. Valid characters include `a-z`, `A-Z`, `0-9`, and `-`. This value is used as the URL prefix for your static app in the format of `https://<APP_NAME>.azurestaticapps.net`.
145+
1. In the *Region* drop-down, choose a region closest to you.
146+
1. Select **Free** from the SKU drop-down.
147147
148148
[Image of static app form]
149149
150150
### Add a GitHub repository
151151
152-
Azure App Service Static App needs access to the repository where your Next.js app lives so it can automatically deploy commits:
152+
The new Static Web Apps account needs access to the repository with your Next.js app so it can automatically deploy commits.
153153
154154
1. Click the **Sign in with GitHub button**
155-
1. Select the **Organization** under which you created the repo for your Next.js project. It can also be your GitHub username.
156-
1. Find the name of the repository you created earlier and select it.
157-
1. Choose **master** as the branch from the *Branch* dropdown.
155+
1. Select the **Organization** under which you created the repo for your Next.js project, which may be your GitHub username.
156+
1. Find and select the name of the repository you created earlier.
157+
1. Choose **master** as the branch from the *Branch* drop-down.
158158
159159
[Image of new repo form]
160160
161161
### Configure the build process
162162
163-
There are few things that Azure App Service Static App can assume--things like automatically installing npm modules and running `npm run build`. There are also few you have to be explicit about, like what folder will the static app be copied to after build so the static site can be served from there.
163+
Azure Static Web Apps is built to automatically carry out common tasks like installing npm modules and running `npm run build` during each deployment. There are, however, a few settings like the application source folder and the build destination folder that you need to configure manually.
164164
165165
1. Click on the **Build** tab to configure the static output folder.
166166
@@ -175,21 +175,21 @@ There are few things that Azure App Service Static App can assume--things like a
175175
1. Once the deployment is completed, click **Go to resource**
176176
1. On the resource screen, click the *URL* link to open your deployed application.
177177
178-
## How to handle dynamic routes
178+
## Configure dynamic routes
179179
180-
Head to your newly deployed site and click on one of the frameworks/libraries. Instead of getting a details page, this time, you get a 404 error page:
180+
Navigate to the newly-deployed site and click on one of the framework or library logos. Instead of getting a details page, you get a 404 error page.
181181
182182
![404 on dynamic routes](./media/deploy-nextjs/404-in-production.png)
183183
184-
The reason for this error is, when we generated a static site with Next.js, we only did so for the home page:
184+
The reason for this error is because Next.js only generated the home page based on the application configuration.
185185
186186
```javascript
187187
module.exports = {
188188
exportTrailingSlash: true,
189189
exportPathMap: function() {
190-
return {
191-
'/': { page: '/' }
192-
};
190+
return {
191+
'/': { page: '/' }
192+
};
193193
}
194194
};
195195
```
@@ -211,8 +211,8 @@ module.exports = {
211211
212212
projects.forEach((project) => {
213213
paths[`/project/${project.slug}`] = {
214-
page: '/project/[path]',
215-
query: { path: project.slug },
214+
page: '/project/[path]',
215+
query: { path: project.slug },
216216
};
217217
});
218218
@@ -222,16 +222,12 @@ module.exports = {
222222
```
223223
224224
> [!NOTE]
225-
> `exportPathMap` is an async function, so you can make a request to an API in this function and use the returned list to generate the paths.
225+
> The `exportPathMap` function is an async function, so you can make a request to an API in this function and use the returned list to generate the paths.
226226
227-
1. Push the new changes to your GitHub repository and wait for a few minutes while GitHub Actions builds your site again. After the build, the 404 error will be gone:
227+
1. Push the new changes to your GitHub repository and wait for a few minutes while GitHub Actions builds your site again. After the build is complete, the 404 error disappears.
228228
229229
![404 on dynamic routes fixed](./media/deploy-nextjs/404-in-production-fixed.png)
230230
231-
## Summary
232-
233-
In this *tutorial*, you created a Next.js static website with dynamic routes and deployed it to App Service Static Site using GitHub Actions.
234231
235-
## Next Steps
236232
> [!div class="nextstepaction"]
237-
> [Set up a custom domain in app service static apps](custom-domain.md)
233+
> [Set up a custom domain](custom-domain.md)

0 commit comments

Comments
 (0)