Azure / Azure/static-web-apps-cli
swa emulator ignoring staticwebapp.config.json routes
- Lingua principale
- TypeScript
- Stelle
- 668
- Fork
- 156
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Esegui l’emulatore sulla porta 4280 con il staticwebapp.config.json fornito e abilita la registrazione dettagliata. Inizia dall’output dell’elaborazione della route per /example, in particolare dai controlli di authorization e userConfig, quindi verifica che gli allowedRoles configurati e il 401 responseOverride vengano applicati prima del proxying. L’attività è completata quando /example raggiunge il reindirizzamento di autenticazione simulato previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- azure, typescript
- Ambito
- authentication, cli
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100