static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

Local web app dev routes with generic char defined in staticwebapp.config.json are not treated as generic

Open eltorio opened this issue 1 year ago • 4 comments

Are you accessing the CLI from the default port :4280 ?

  • [x] No, I am using a different port number (--port) and accessing the CLI from that port
  • [ ] Yes, I am accessing the CLI from port :4280

Describe the bug When I define a route with /AAA* , /AAA* is proxied to the defined rewrite but /AAATEST is proxied to the frontend app

To Reproduce npx @azure/static-web-apps-cli start https://localhost:5173 --swa-config-location ./ -s -e localhost.internal.tld.pem -k localhost.internal.tld.key -p 8788 --api-location ./api -t 120 --run 'npm run dev'

staticwebapp.config.json

{
    "globalHeaders": {
        "content-security-policy": "default-src https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'"
    },
    "routes": [
        {
            "route": "/GOOGLE",
            "redirect": "https://www.google.fr",
            "statusCode": 302
        },
        {
            "route": "/!TEST",
            "rewrite": "/api/redirect"
        },
        {
            "route": "/AAA*",
            "rewrite": "/api/redirect"
        }
    ]
}

Expected behavior browsing to https://localhost.internal.tld:8788/AAATEST must be rewritten to /api/redirect as explained in the documentation https://learn.microsoft.com/fr-fr/azure/static-web-apps/configuration#wildcards

Bugged behavior browsing to https://localhost.internal.tld:8788/AAATEST [swa] GET https://localhost:5173/AAATEST (proxy)

browsing to https://localhost.internal.tld:8788/AAA*

[swa] GET http://localhost:7071/api/redirect (proxy)
[api] [2022-10-05T05:53:41.729Z] Executing HTTP request: {
[api] [2022-10-05T05:53:41.729Z]   requestId: "f6ed30b0-5580-4395-89f7-e34bd1e7e2ad",
[api] [2022-10-05T05:53:41.729Z]   method: "GET",
[api] [2022-10-05T05:53:41.729Z]   userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",
[api] [2022-10-05T05:53:41.729Z]   uri: "/api/redirect"
[api] [2022-10-05T05:53:41.729Z] }
[api] [2022-10-05T05:53:41.730Z] Executing 'Functions.redirect' (Reason='This function was programmatically called via the host APIs.', Id=c3549609-e9a1-483c-9f0d-81593625eb5a)
[api] [2022-10-05T05:53:41.732Z] to:AA*
[api] [2022-10-05T05:53:41.735Z] Received FunctionInvocationRequest
[api] [2022-10-05T05:53:41.899Z] Executed 'Functions.redirect' (Succeeded, Id=c3549609-e9a1-483c-9f0d-81593625eb5a, Duration=169ms)
[api] [2022-10-05T05:53:41.901Z] Executed HTTP request: {
[api] [2022-10-05T05:53:41.901Z]   requestId: "f6ed30b0-5580-4395-89f7-e34bd1e7e2ad",
[api] [2022-10-05T05:53:41.901Z]   identities: "",
[api] [2022-10-05T05:53:41.901Z]   status: "500",
[api] [2022-10-05T05:53:41.901Z]   duration: "172"
[api] [2022-10-05T05:53:41.901Z] }
[swa] GET https://localhost.lesmuids.windows:8788/api/redirect - 500

500 status is my normal behavior (the function return status 500 because AAA* is not allowed)

Desktop (please complete the following information):

  • OS: MacOS
  • Version 10.15.7

Additional context

swa -version
Welcome to Azure Static Web Apps CLI (1.0.2)

eltorio avatar Oct 05 '22 06:10 eltorio

@Reshmi-Sriram I've just tested a deployement on Azure and it works perfectly, so the bug is only on the swa emulator. Ronan

eltorio avatar Oct 05 '22 06:10 eltorio

@Reshmi-Sriram I've created a repo to reproduce it: https://github.com/highcanfly-club/azure-swa-clib-bug-580 it has a simple config

{
    "globalHeaders": {
        "content-security-policy": "default-src https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'"
    },
    "routes": [
        {
            "route": "/!*",
            "rewrite": "/api/redirect"
        }
    ]
}
git clone https://github.com/highcanfly-club/azure-swa-clib-bug-580.git && cd azure-swa-clib-bug-580/
npm i
npm start
# browse https://localhost:8788/!AZURE
# swa must proxy it to http://localhost:7071/api/redirect 
# but it proxies to https://localhost:5173

eltorio avatar Oct 05 '22 07:10 eltorio

Hey @eltorio SWA_CLI maynot match exactly with the Azure Static web apps. So, please try deploying this on SWA and verify. However, we are trying to close these differences and match the SWA as closely as possible.

sgollapudi77 avatar Oct 06 '22 06:10 sgollapudi77

Hi @sgollapudi77 , Thank you for your answer. I know that the platforms do not match exactly. This routing works perfectly on SWA and not locally. It is a blocking bug since we cannot process some local testing and so it is a Q/A problem. For example for education purpose we demonstrate it https://kiik.cf use exactly this routing. https://kiik.cf/!PTGR0 redirect to https://portal.azure.com

eltorio avatar Oct 06 '22 07:10 eltorio