Report this

What is the reason for this report?

DO Apps - "App Spec" .yaml help with adding CORS

Posted on June 14, 2023

Hello I have a static App on DO using the App importing from a GIT repository.

I have followed the instructions here including the .yaml file example but it keeps getting rejected

https://docs.digitalocean.com/products/app-platform/reference/app-spec/

alerts:
- rule: DEPLOYMENT_FAILED
- disabled: true
  rule: DOMAIN_FAILED
- disabled: true
  rule: DEPLOYMENT_STARTED
- disabled: true
  rule: DEPLOYMENT_CANCELED
- rule: DEPLOYMENT_LIVE
- disabled: true
  rule: DOMAIN_LIVE
domains:
- domain: mywebsite.uk
  type: PRIMARY
ingress:
  rules:
  - component:
      name: mywebsite-web-app-staging
    match:
      path:
        prefix: /
name: mywebsite-app-staging
region: lon
services:
- cors:
    allow_origins:
    - prefix: https://api.mywebsite.com
static_sites:
- catchall_document: index.html
  environment_slug: html
  github:
    branch: main
    deploy_on_push: true
    repo: xxxx/mywebsite-web-app-staging
  name: mywebsite-web-app-staging
  source_dir: /

Above is a copy of the .yaml the system produces with only the

services:
- cors:
    allow_origins:
    - prefix: https://api.mywebsite.com

added.

Thanks



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey Phil,

I’ve noticed that this is a duplicate question and my colleague Greg has already answered this here:

https://www.digitalocean.com/community/questions/adding-cors-to-app-spec-yaml-in-a-serverless-static-app

The CORS policies have moved under ingress rules. When you add a rule for your static site component, e.g.:

ingress:
  rules:
  - component:
      name: mywebsite-web-app-live
    match:
      path:
        prefix: /

Add your CORS policy in the rule:

ingress:
  rules:
  - component:
      name: mywebsite-web-app-live
    match:
      path:
        prefix: /
    cors:
      allow_origins:
      - prefix: https://api.mywebsite.co.uk
      - prefix: https://*.mywebsite.co.uk
      - prefix: https://mywebsite.co.uk

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.