0

I have an Azure static web app with the staticwebapp.config.json like so:

"routes": [
  {
    "route": "/*",
    "allowedRoles": ["authenticated"]
  }
]
"navigationFallback": {
  "rewrite": "index.html",
  "exclude": ["/static/media/*.{png,jpg,gif,svg}", "/static/css/*"]
}

This works and all routes need to go through auth. Now, I want to add an exception to the /health route to allow for health check services to see if my site is up and running. How can I do this? I tried adding a route like this:

"routes": [
  {
    "route": "/health",
    "allowedRoles": ["anonymous"]
  },
  {
    "route": "/*",
    "allowedRoles": ["authenticated"]
  }
]
"navigationFallback": {
  "rewrite": "index.html",
  "exclude": ["/static/media/*.{png,jpg,gif,svg}", "/static/css/*"]
}

But that does not work, /health route still requires authentication.

7
  • please share the code Commented Feb 22, 2024 at 4:05
  • That is the code, Azure static web apps have a config file that is used to determine the authentication and access to routes. You can see the docs here - learn.microsoft.com/en-us/azure/static-web-apps/configuration but in classic MS style, they either do not provide for a solution for my problem or their documentation is sorely lacking. Commented Feb 22, 2024 at 14:45
  • which language you are looking for like react etc Commented Feb 22, 2024 at 15:29
  • It's a react site, yes Commented Feb 22, 2024 at 15:42
  • What type of authentication you are looking for . You asked for health check? /health will work when we have code like / . Here is the example of routing. Commented Feb 22, 2024 at 16:00

2 Answers 2

0

What do you have behind the /health ?

It may be the navigationFallback that is redirecting you to index.html which requires authentication.

You can define a fallback rule by adding a navigationFallback section. The following example returns /index.html for all static file requests that don't match a deployed file. official doc

To be sure, add /health to the excluded path:

"exclude": ["/static/media/*.{png,jpg,gif,svg}", "/static/css/*", "/health"]

It is not due to the order of routes in your config

Rule evaluation stops at the first match

Sign up to request clarification or add additional context in comments.

1 Comment

Tried this as well but the health route does not work
0

From the example given here, Configure SWA, this most closely matches your requirement..

{ "route": "/calendar*", "rewrite": "/calendar.html" }

so you may need the wildcard at the end as indicated by

Wildcard pattern

...

The calendar.html file can then use client-side routing to serve a different view for URL variations like /calendar/january/1, /calendar/2020, and /calendar/overview.

Note

A route pattern of /calendar/* matches all requests under the /calendar/ path. However, it won't match requests for the paths /calendar or /calendar.html. Use /calendar* to match all requests that begin with /calendar.

1 Comment

I was really hoping this was the answer but I tried and it does not work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.