Skip to content

Commit 28ab1dd

Browse files
authored
Apply suggestions from code review
1 parent 410b536 commit 28ab1dd

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

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

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -324,48 +324,51 @@ Your Next.js project can be configured to have custom handling of routes with re
324324
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:
325325
326326
1. Exclude routes starting with `.swa` in your `middleware.ts` (or `.js`) file in your middleware configuration.
327-
```js
328-
export const config = {
329-
matcher: [
330-
/*
331-
* Match all request paths except for the ones starting with:
332-
* - .swa (Azure Static Web Apps)
333-
*/
334-
'/((?!.swa).*)',
335-
],
336-
}
337-
```
327+
328+
```js
329+
export const config = {
330+
matcher: [
331+
/*
332+
* Match all request paths except for the ones starting with:
333+
* - .swa (Azure Static Web Apps)
334+
*/
335+
'/((?!.swa).*)',
336+
],
337+
}
338+
```
338339
339340
1. Configure your redirects in `next.config.js` to exclude routes starting with `.swa`
340-
```js
341-
module.exports = {
342-
async redirects() {
343-
return [
344-
{
345-
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
346-
destination: '<YOUR REDIRECT RULE>',
347-
permanent: false,
348-
},
349-
]
350-
},
351-
};
352-
```
341+
342+
```js
343+
module.exports = {
344+
async redirects() {
345+
return [
346+
{
347+
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
348+
destination: '<YOUR REDIRECT RULE>',
349+
permanent: false,
350+
},
351+
]
352+
},
353+
};
354+
```
353355
354356
1. Configure your rewrites in `next.config.js` to exclude routes starting with `.swa`
355-
```js
356-
module.exports = {
357-
async rewrites() {
358-
return {
359-
beforeFiles: [
360-
{
361-
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
362-
destination: '<YOUR REWRITE RULE>',
363-
}
364-
]
365-
}
366-
},
367-
};
368-
```
357+
358+
```js
359+
module.exports = {
360+
async rewrites() {
361+
return {
362+
beforeFiles: [
363+
{
364+
source: '/((?!.swa).*)<YOUR MATCHING RULE>',
365+
destination: '<YOUR REWRITE RULE>',
366+
}
367+
]
368+
}
369+
},
370+
};
371+
```
369372
These code snippets exclude paths that start with `.swa` from being handled by your custom routing or middleware. These rules ensure that the paths resolve as expected during deployment validation.
370373
371374
## Enable logging for Next.js

0 commit comments

Comments
 (0)