Azure / Azure/static-web-apps-cli

swa emulator ignoring staticwebapp.config.json routes

Open
#630 4 comments 0 reactions 0 assignees View on GitHub
status: investigating
Dominant language
TypeScript
Stars
668
Forks
156
PR merge metrics
No merged PRs in 30d

Description

SWA_CLI_VERSION: 1.0.4

**Are you accessing the CLI from the default port `:4280` ?**
- [X] Yes, I am accessing the CLI from port `:4280`

**Describe the bug**
I have a very simple staticwebapp.config.json with one secured route that _should_ redirect but does not.

```
{
"$schema": "https://json.schemastore.org/staticwebapp.config.json",
"routes": [
{
"route": "/example",
"allowedRoles": ["rolethatdoesntexist"]
}
],
"responseOverrides": {
"401": {
"redirect": "/.auth/login/twitter",
"statusCode": 302
}
},
"navigationFallback": {
"rewrite": "index.html",
"exclude": [
"/images/*.{png,jpg,gif}",
"/css/*"
]
}
}
```

I've tried a million variations of the route, even tried to add a `/*` route to redirect all URLs, but no routes appear to work. This staticwebapp.config.json works when deployed to Azure, just not when using the emulator, making it hard to develop.

When using silly verbose mode, this is printed when handling the route:

```
[swa] --------------------------------------------------------
[swa] ------------------- processing route -------------------
[swa] --------------------------------------------------------
[swa] processing /example
[swa] checking for matching route
[swa] checking auth request
[swa] - not an auth request
[swa] checking function request
[swa] - not a function request
[swa] checking HTTP method: GET
[swa] - method is valid (allow-list: GET,HEAD,OPTIONS)
[swa] checking for query params
[swa] checking rewrite auth login request
[swa] checking rewrite auth logout request
[swa] checking authorizations for route
[swa] - no matching rule
[swa] - access authorized
[swa] using userConfig
[swa] - userConfig:
[swa] checking storage content
[swa] remote dev server detected.
[swa] - url: /example
[swa] - target: http://localhost:5173
[swa] customUrl: false
[swa] is4xx: false
[swa] remote dev server detected. Proxying request
[swa] - url: /example
[swa] - code: 200
[swa] GET http://localhost:5173/example (proxy)
[swa] getting response from dev server
[swa] GET http://localhost:4280/example - 304
```

**Expected behavior**
I expect the URL `http://localhost:4280/example` to route to authentication. (Or at least the mocked authentication)

**Screenshots**

**Desktop (please complete the following information):**

- OS: Windows 10
- Version: 19044

**Additional context**
This may be related -- but as far as I can tell from other issue threads, it can be ignored?

```
[swa] Loading staticwebapp.config.json schema...
[swa] Failed to load schema from https://json.schemastore.org/staticwebapp.config.json
[swa] WARNING: Failed to load staticwebapp.config.json schema. Continuing without validation!
```

If I move the staticwebapp.config.json from the directory, it shows a different error that it can't find it, so I at least know it's finding the file where it is.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.