Can you deploy both static assets and back-end apis in the same worker?

I'm trying to deploy a Hugo static site with a contact form, and have the contact form interact with an /api/contact worker deployed from the same repository. is this possible with wrangler?
I asked the AI overlords for help, and this is what it spit out for me:
# Main wrangler.toml for multi-worker project
compatibility_date = "2025-05-28"
preview_urls = true
workers_dev = true

[env.staging.vars]
ENVIRONMENT = "staging"

# website Worker (serves static assets)
[[workers]]
name = "website"
main = "src/main-worker.js"
type = "javascript.module"

[workers.site]
bucket = "./public"

[[workers.kv_namespaces]]
binding = "__STATIC_CONTENT"
id = "kv_id_long_string"

# Contact Form Worker
[[workers]]
name = "contact-form-worker"
main = "cloudflare-worker-contact-form/src/index.js"
compatibility_date = "2024-01-01"
type = "javascript.module"

[workers.vars]
FILLOUT_FORM_ID = "form_id"
FILLOUT_FIELD_NAME_ID = "name_id"
FILLOUT_FIELD_EMAIL_ID = "email_id"
FILLOUT_FIELD_COMPANY_ID = "company_id"
FILLOUT_FIELD_PHONE_ID = "phone_idd"
FILLOUT_FIELD_SERVICES_ID = "services_id"
FILLOUT_FIELD_MESSAGE_ID = "meessage_id"

# Secrets for the contact form worker
secrets = ["FILLOUT_API_KEY"]

# Routes for the contact form worker
routes = ["website_url/api/contact"]
# Main wrangler.toml for multi-worker project
compatibility_date = "2025-05-28"
preview_urls = true
workers_dev = true

[env.staging.vars]
ENVIRONMENT = "staging"

# website Worker (serves static assets)
[[workers]]
name = "website"
main = "src/main-worker.js"
type = "javascript.module"

[workers.site]
bucket = "./public"

[[workers.kv_namespaces]]
binding = "__STATIC_CONTENT"
id = "kv_id_long_string"

# Contact Form Worker
[[workers]]
name = "contact-form-worker"
main = "cloudflare-worker-contact-form/src/index.js"
compatibility_date = "2024-01-01"
type = "javascript.module"

[workers.vars]
FILLOUT_FORM_ID = "form_id"
FILLOUT_FIELD_NAME_ID = "name_id"
FILLOUT_FIELD_EMAIL_ID = "email_id"
FILLOUT_FIELD_COMPANY_ID = "company_id"
FILLOUT_FIELD_PHONE_ID = "phone_idd"
FILLOUT_FIELD_SERVICES_ID = "services_id"
FILLOUT_FIELD_MESSAGE_ID = "meessage_id"

# Secrets for the contact form worker
secrets = ["FILLOUT_API_KEY"]

# Routes for the contact form worker
routes = ["website_url/api/contact"]
4 Replies
toonjunkie1
toonjunkie1OP6mo ago
the idea is that rather than embedding the slower-loading form directly from fillout, I'll create a form in my static site, and the submit triggers JS that packages the form up and sends to a worker, where the worker has the API key for Fillout and submits the form directly to their API. this way the site loads fast as a static site does, and I don't need to have the embed AND i don't need to try figuring out how to allow the embedded fillout form in the content security policy.
Hello, I’m Allie!
That doesn’t look like valid syntax for a wrangler.toml?
Hello, I’m Allie!
Cloudflare Docs
Configuration
Use a configuration file to customize the development and deployment setup for your Worker project and other Developer Platform products.
toonjunkie1
toonjunkie1OP6mo ago
Thanks for that link - I reworked the toml and i'm getting closer:
name = "my_worker"
main = "src/index.js"
compatibility_date = "2025-05-28"

# Static assets configuration
[assets]
directory = "./public"
binding = "ASSETS"

# Staging environment
[env.staging]
name = "my_worker_staging"
vars = { ENVIRONMENT = "staging" }
# Optionally override asset settings if needed
[env.staging.assets]
directory = "./public"
binding = "ASSETS"

# Production environment
[env.production]
name = "my_worker"
vars = { ENVIRONMENT = "production" }
[env.production.assets]
directory = "./public"
binding = "ASSETS"
name = "my_worker"
main = "src/index.js"
compatibility_date = "2025-05-28"

# Static assets configuration
[assets]
directory = "./public"
binding = "ASSETS"

# Staging environment
[env.staging]
name = "my_worker_staging"
vars = { ENVIRONMENT = "staging" }
# Optionally override asset settings if needed
[env.staging.assets]
directory = "./public"
binding = "ASSETS"

# Production environment
[env.production]
name = "my_worker"
vars = { ENVIRONMENT = "production" }
[env.production.assets]
directory = "./public"
binding = "ASSETS"
Thank you for your help!

Did you find this page helpful?