Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Web Apps emulator expects Data Api in port 5000 but it is starting in port 8080 #935

Open
1 task
jmservera opened this issue Mar 2, 2025 · 1 comment

Comments

@jmservera
Copy link

jmservera commented Mar 2, 2025

Before filing this issue, please ensure you're using the latest CLI by running swa --version and comparing to the latest version on npm.

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

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

Make sure you are accessing the URL printed in the console when running swa start!

ℹ️ NOTE: Make sure to enable debug logs when running any swa commands using --verbose=silly

Describe the bug
When trying to use any graph query the server returns 502 Bad Gateway

It looks like the new dataApiBuilder v1.3.19 uses port 8080 as default instead of port 5000 like before, and it stopped working with the swa emulator.

See in the variables

  - SWA_CLI_DATA_API_LOCATION: /workspaces/user/swa-db-connections
  - SWA_CLI_DATA_API_PORT: 5000

But during the startup we can see:

info: Azure.DataApiBuilder.Service.Startup[0]
      Successfully completed runtime initialization.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://[::]:8080

And here a snippet of the logs when it tries to access the database

POST http://0.0.0.0:5000/graphql (proxy)
injecting headers to Data-api request:
 - x-ms-request-id: SWA-CLI-FH160YON79
injecting client principal to Functions request:
decoding StaticWebAppsAuthCookie cookie
 - StaticWebAppsAuthCookie decoded: {"userId":"85bcb74cd35899cb51ccc81296e2615b","userRoles":["anonymous","authenticated"],"claims":[],"identityProvider":"aad","userDetails":"[email protected]"}
 - X-MS-CLIENT-PRINCIPAL: eyJ1c2VySWQiOiI4NWJjYjc0Y2QzNTg5OWNiNTFjY2M4MTI5NmUyNjE1YiIsInVzZXJSb2xlcyI6WyJhbm9ueW1vdXMiLCJhdXRoZW50aWNhdGVkIl0sImlkZW50aXR5UHJvdmlkZXIiOiJhYWQiLCJ1c2VyRGV0YWlscyI6Imptc2VydmVyYUBvdXRsb29rLmNvbSJ9
 - Authorization: Bearer eyJ1c2VySWQiOiI4NWJjYjc0Y2QzNTg5OWNiNTFjY2M4MTI5NmUyNjE1YiIsInVzZXJSb2xlcyI6WyJhbm9ueW1vdXMiLCJhdXRoZW50aWNhdGVkIl0sImlkZW50aXR5UHJvdmlkZXIiOiJhYWQiLCJ1c2VyRGV0YWlscyI6Imptc2VydmVyYUBvdXRsb29rLmNvbSJ9
✖  ↳ POST http://0.0.0.0:5000/graphql - 502 (Bad Gateway)
- error:
  - errno: -111
  - code: ECONNREFUSED
  - syscall: connect
  - address: 0.0.0.0
  - port: 5000

To Reproduce
Steps to reproduce the behavior:

  1. use the data api location parameter: --data-api-location "../swa-db-connections"
  2. Use any graph query to query the data using the proxy
  3. See error

Here's a snippet of the code I'm using for running a query:

async function execQuery(query: string, data?: QueryVariables): Promise<any> {
  const createQuery = {
    query: query,
    variables: data,
  };

  const endpoint = "/data-api/graphql";
  const result = await fetch(endpoint, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(createQuery),
  });

  return await result.json();
}

Expected behavior

Identify the DataApiBuilder port instead of using the fixed 5000

Desktop (please complete the following information):

  • OS: ubuntu devcontainer
  • Version: mcr.microsoft.com/devcontainers/dotnet:8.0-jammy

Additional context

This worked a few months ago, I opened my devcontainer that I didn't modify, but it downloaded a new version of the dataApiBuilder.

This is the script I'm using to run (I'm ignoring my functions by now until the database works again):

#!/bin/bash
. .env

>&2 echo $(hugo -M --printI18nWarnings | grep i18n)

# check if first parameter is "prod"

if [ "$1" == "prod" ]; then
    echo "Starting staging server"
    run="hugo server -M -e staging -p 1313 --disableFastRender"
else
    echo "Starting development server"
    run="hugo server -M -e development -D -p 1313"
fi

# Workaround until this issue is fixed: https://github.com/Azure/azure-functions-core-tools/issues/3594sw
# dotnet clean ../backend/functions

AzureWebJobsStorage=$STORAGE_CONNECTION_STRING swa start http://localhost:1313 --run "$run" -V silly --data-api-location "../swa-db-connections" # --api-location ../backend/functions

Log:

Starting development server

Welcome to Azure Static Web Apps CLI (2.0.4)

Getting config file options from "swa-cli.config.json"...
Config file does not exist at "swa-cli.config.json"
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

Checking if 0.0.0.0:4280 is accepting TCP connections...
Port 4280 is available. Use it.
Resolved port number: 4280
appDevserverUrl provided, we will try connect to dev server at .
Data Api Folder found: /workspaces/user/swa-db-connections
Trying to read workflow config with values:
 - appLocation: /workspaces/user/www
 - outputLocation: http://localhost:1313
 - apiLocation: <undefined>
No workflow config folder found at /workspaces/user/www/.github/workflows
Validating user workflow config (BEFORE):
 - appLocation: /workspaces/user/www
 - outputLocation: http://localhost:1313
 - apiLocation: <undefined>
Validating user workflow config (AFTER):
 - appLocation: /workspaces/user/www
 - apiLocation: <undefined>
 - outputLocation: http://localhost:1313
 - dataApiLocation: <undefined>
User workflow config:
 - appLocation: /workspaces/user/www
 - apiLocation: <undefined>
 - outputLocation: http://localhost:1313
 - dataApiLocation: <undefined>
Running dab --version
dab is not installed.
Setting executable permissions for data-api-builder binary
DataApiBuilder found: /home/vscode/.swa/dataApiBuilder/1.3.19/Microsoft.DataApiBuilder. Using this to start data-api server
Running cd "/workspaces/user/swa-db-connections" && "/home/vscode/.swa/dataApiBuilder/1.3.19/Microsoft.DataApiBuilder" start -c staticwebapp.database.config.json --no-https-redirect
Starting the SWA emulator with the following configuration:
- ssl:
  - 0: false
  - 1: <undefined>
  - 2: <undefined>
- env:
  - SWA_RUNTIME_CONFIG_LOCATION: /workspaces/user/www
  - SWA_RUNTIME_WORKFLOW_LOCATION: <undefined>
  - SWA_CLI_DEBUG: silly
  - SWA_CLI_API_PORT: 7071
  - SWA_CLI_APP_LOCATION: /workspaces/user/www
  - SWA_CLI_OUTPUT_LOCATION: http://localhost:1313
  - SWA_CLI_API_LOCATION: <undefined>
  - SWA_CLI_DATA_API_LOCATION: /workspaces/user/swa-db-connections
  - SWA_CLI_DATA_API_PORT: 5000
  - SWA_CLI_HOST: 0.0.0.0
  - SWA_CLI_PORT: 4280
  - SWA_CLI_APP_SSL: false
  - SWA_CLI_APP_SSL_CERT: <undefined>
  - SWA_CLI_APP_SSL_KEY: <undefined>
  - SWA_CLI_STARTUP_COMMAND: hugo server -M -e development -D -p 1313
  - SWA_CLI_VERSION: 2.0.4
  - SWA_CLI_SERVER_TIMEOUT: 60
  - SWA_CLI_OPEN_BROWSER: false
- commands:
  - swa: node "/usr/local/share/nvm/versions/node/v18.20.7/lib/node_modules/@azure/static-web-apps-cli/dist/msha/server.js"
  - api: <undefined>
  - dataApi: cd "/workspaces/user/swa-db-connections" && "/home/vscode/.swa/dataApiBuilder/1.3.19/Microsoft.DataApiBuilder" start -c staticwebapp.database.config.json --no-https-redirect
  - run: cd "/workspaces/user/www" && hugo server -M -e development -D -p 1313
Watching for changes in /workspaces/user/www/{assets,content,i18n,layouts,package.json,static,themes}
Watching for config changes in /workspaces/user/www/hugo.toml, /workspaces/user/www/go.mod
Start building sites … 
hugo v0.145.0-666444f0a52132f9fec9f71cf25b441cc6a4f355+extended linux/amd64 BuildDate=2025-02-26T15:41:25Z VendorInfo=gohugoio

WARN  Dart Sass: DEPRECATED [import]: /workspaces/user/www/themes/hugo-scroll/assets/css/_index.scss:1:8: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import
WARN  Dart Sass: DEPRECATED [import]: /workspaces/user/www/themes/hugo-scroll/assets/css/_index.scss:4:8: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import
WARN  Dart Sass: DEPRECATED [import]: /workspaces/user/www/themes/hugo-scroll/assets/css/_index.scss:7:8: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import
WARN  Dart Sass: DEPRECATED [import]: /workspaces/user/www/themes/hugo-scroll/assets/css/_index.scss:10:8: Sass @import rules are deprecated and will be removed in Dart Sass 3.0.0.

More info and automated migrator: https://sass-lang.com/d/import

                   | ES  | EN  | FR   
-------------------+-----+-----+------
  Pages            |  24 |  21 |  21  
  Paginator pages  |   0 |   0 |   0  
  Non-page files   |   0 |   0 |   0  
  Static files     | 130 | 130 | 130  
  Processed images |   0 |   0 |   0  
  Aliases          |   1 |   0 |   0  
  Cleaned          |   0 |   0 |   0  

Built in 761 ms
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:1313/ (bind address 127.0.0.1) 
Press Ctrl+C to stop
Information: Microsoft.DataApiBuilder 1.3.19
Information: User provided config file: staticwebapp.database.config.json
Loading config file from /workspaces/user/swa-db-connections/staticwebapp.database.config.json.
Information: Loaded config file: staticwebapp.database.config.json
Information: Setting default minimum LogLevel: Debug for Development mode.
Starting the runtime engine...
Redirecting to https is disabled.
Loading config file from /workspaces/user/swa-db-connections/staticwebapp.database.config.json.
Reading content from staticwebapp.config.json...
Parsing /workspaces/user/www/static/staticwebapp.config.json...
Monitoring config: staticwebapp.database.config.json for hot-reloading.
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
      Storing keys in a directory '/home/vscode/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. For more information go to https://aka.ms/aspnet/dataprotectionwarning
Content parsed successfully
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]
      User profile is available. Using '/home/vscode/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.

Found configuration file:
  /workspaces/user/www/static/staticwebapp.config.json

Validating dev server config:
 - url: http://localhost:1313
 - timeout: 60
Checking if localhost:1313 is accepting TCP connections...

Using dev server for static content:
  http://localhost:1313

Azure Static Web Apps emulator started at http://0.0.0.0:4280. Press CTRL+C to exit.


info: Azure.DataApiBuilder.Service.Startup[0]
      Successfully completed runtime initialization.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /workspaces/user/swa-db-connections

And here's the output of netstat -panout (see, no port 5000 being used, but 8080 for the data api)

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     Timer
tcp        0      0 0.0.0.0:4280            0.0.0.0:*               LISTEN      19501/node           off (0.00/0/0)
tcp        0      0 127.0.0.1:43107         0.0.0.0:*               LISTEN      281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:1313          0.0.0.0:*               LISTEN      19505/hugo           off (0.00/0/0)
tcp        0      0 127.0.0.1:1313          127.0.0.1:43762         ESTABLISHED 19505/hugo           keepalive (3.34/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:56248         CLOSE_WAIT  281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:43832         127.0.0.1:1313          ESTABLISHED 19501/node           keepalive (3.82/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:34774         ESTABLISHED 503/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:1313          127.0.0.1:43924         ESTABLISHED 19505/hugo           keepalive (3.34/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:34770         ESTABLISHED 281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:57500         127.0.0.1:1313          ESTABLISHED 281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:1313          127.0.0.1:57500         ESTABLISHED 19505/hugo           keepalive (2.06/0/0)
tcp        0      0 127.0.0.1:34774         127.0.0.1:43107         ESTABLISHED 445/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:33528         CLOSE_WAIT  281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:55246         CLOSE_WAIT  281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:1313          127.0.0.1:43832         ESTABLISHED 19505/hugo           keepalive (3.34/0/0)
tcp        0      0 127.0.0.1:1313          127.0.0.1:43932         ESTABLISHED 19505/hugo           keepalive (12.94/0/0)
tcp        0      0 127.0.0.1:49872         127.0.0.1:43107         ESTABLISHED 20181/node           off (0.00/0/0)
tcp        0      0 172.17.0.2:57902        140.82.121.5:443        ESTABLISHED 503/node             keepalive (44.53/0/0)
tcp        0      0 127.0.0.1:34770         127.0.0.1:43107         ESTABLISHED 416/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:56938         127.0.0.1:43107         ESTABLISHED 21783/node           off (0.00/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:56938         ESTABLISHED 281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:43924         127.0.0.1:1313          ESTABLISHED 19501/node           keepalive (3.90/0/0)
tcp        0      0 172.17.0.2:57886        140.82.121.5:443        ESTABLISHED 503/node             keepalive (43.98/0/0)
tcp        0      0 127.0.0.1:43762         127.0.0.1:1313          ESTABLISHED 19501/node           keepalive (3.82/0/0)
tcp        0      0 127.0.0.1:43932         127.0.0.1:1313          ESTABLISHED 19501/node           keepalive (3.26/0/0)
tcp        0      0 172.17.0.2:57910        140.82.121.5:443        ESTABLISHED 503/node             keepalive (44.89/0/0)
tcp        0      0 127.0.0.1:1313          127.0.0.1:40418         ESTABLISHED 19505/hugo           keepalive (14.22/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:45762         CLOSE_WAIT  281/node             off (0.00/0/0)
tcp        0      0 127.0.0.1:40418         127.0.0.1:1313          ESTABLISHED 281/node             off (0.00/0/0)
tcp        0      0 172.17.0.2:53456        20.189.172.33:443       TIME_WAIT   -                    timewait (29.48/0/0)
tcp        0      0 172.17.0.2:47196        140.82.113.22:443       ESTABLISHED 503/node             keepalive (45.94/0/0)
tcp        0      0 127.0.0.1:43107         127.0.0.1:49872         ESTABLISHED 281/node             off (0.00/0/0)
tcp6       0      0 :::8080                 :::*                    LISTEN      19503/Microsoft.Dat  off (0.00/0/0)
@jmservera
Copy link
Author

jmservera commented Mar 2, 2025

After playing around with DAB and running it manually to test it, I've managed to workaround the issue by setting an environment value like explained here: Azure/data-api-builder#1425

So now my command line looks like this, to enforce the port 5000 usage:

ASPNETCORE_URLS="http://localhost:5000" AzureWebJobsStorage=$STORAGE_CONNECTION_STRING swa start http://localhost:1313 --run "$run" -V --data-api-location "../swa-db-connections" # --api-location ../backend/functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant