Automatic Service Binding on `wrangler publish`
# workers-help
k
I defined service bindings in the wrangler.toml for a project like so:
Copy code
services = [
  { binding = "blockstore_service", service = "blucket-blockstore-staging", environment = "staging" },
  { binding = "blockstore_service", service = "blucket-blockstore-production", environment = "production" },
  { binding = "blockstore_service", service = "blucket-blockstore-dev", environment = "dev" },
]
After publishing, however, I don't see the service bound. Is this expected? What's the point of specifying bindings in wrangler.toml if so?
h
Each binding should be different
k
huh. I wan under the impression I could keep bindings constant -- that's kinda required for calling services from the JS api
Otherwise I need to case switch like if (wrangler_env == staging) env.service_staging.fetch()
for downstream services
For more context here's my wrangler.toml
Copy code
name = "blucket-api"
main = "src/index.js"
compatibility_date = "2023-05-12"
compatibility_flags = [ "nodejs_compat" ]

services = [
  { binding = "blockstore_service", service = "blucket-blockstore-staging", environment = "production" },
  { binding = "blockstore_service", service = "blucket-blockstore-production", environment = "production" },
]

# Production environment.
[env.production]
name = "blucket-api-production"
# Configure this to your own account.
account_id = "3648328bb7b24838c70d601e79891d98"
# Configure this to your own domain.
route = "blucket.alex1883.workers.dev"

# [[env.production.services]]
# binding = "blockstore_service"
# service = "blucket-blockstore-production"

# Staging environment.
[env.staging]
name = "blucket-api-staging"
# Configure this to your own account.
account_id = "3648328bb7b24838c70d601e79891d98"
# Configure this to your own domain.
route = "blucket-staging.alex1883.workers.dev"


# [[env.staging.services]]
# binding = "blockstore_service"
# service = "blucket-blockstore-staging"

[env.dev]
name = "blucket-api-dev"

[[env.dev.services]]
binding = "blockstore_service"
service = "blucket-blockstore-dev"
Update: Removing all bindings expect for production still doesn't auto gen bindings between services
h
Try this:
Copy code
json
{
  "name": "blucket-api",
  "main": "src/index.js",
  "compatibility_date": "2023-05-12",
  "compatibility_flags": [
    "nodejs_compat"
  ],
  "env": {
    "production": {
      "name": "blucket-api-production",
      "account_id": "3648328bb7b24838c70d601e79891d98",
      "route": "blucket.alex1883.workers.dev",
      "services": [{
        "binding": "blockstore_service",
        "service": "blucket-blockstore-production",
      }]
    },
    "staging": {
      "name": "blucket-api-staging",
      "account_id": "3648328bb7b24838c70d601e79891d98",
      "route": "blucket-staging.alex1883.workers.dev",
      "services": [{
        "binding": "blockstore_service",
        "service": "blucket-blockstore-staging"
      }]
    },
    "dev": {
      "name": "blucket-api-dev",
      "services": [{
        "binding": "blockstore_service",
        "service": "blucket-blockstore-dev"
      }]
    }
  }
}
k
will do 🫡
2 Views