swa emulator ignoring staticwebapp.config.json routes
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: <undefined>
[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.
For what it's worth, I'm running swa start and this is my swa-cli.config.json
{
"$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
"configurations": {
"local": {
"appLocation": "ui",
"apiLocation": "api\\FunctionsProjectName\\src",
"start" : {
"appDevserverUrl": "http://localhost:5173",
"apiDevserverUrl": "http://localhost:7071",
"printConfig": "true",
"verbose": "silly"
}
}
}
}
The frontend (React) is running and the functions are being run via visual studio on these ports.
Additional info, since the config file I used as an example is role-authentication secured, checking my authentication status via
http://localhost:4280/.auth/me just shows clientPrincipal: null.
The same thing happens if I just made the route a redirect route and not an allowedRoles check, the route appears to be ignored (or not matched) completely.
i think i have a similar problem with my SvelteKit application. I managed to run everything nicely when using the build directory. However, in dev mode I'm getting 304s on basically every file in my project. Currently I need to build the app for every change which is a bit annoying.
@i-love-code I just tried this with version 1.1.2 of the SWA CLI and it worked so you may want to try an updated version if possible.