A. L
A. L

Reputation: 12649

Google App Engine CORS “Error parsing ./app.yaml: Unknown url handler type”

I'm trying to apply CORS to one of my app engines, but I'm encountering an error. I've tried looking at the recommendations for other answers (spacing) but it still errors:

app.yaml

runtime: nodejs10

env_variables:
  NODE_ENV: production
  CLOUD_SQL_CONNECTION_NAME: domain-name-server:australia-southeast1:db_name

handlers:  
- url: /.*
  http_headers:
    Access-Control-Allow-Origin: https://domain_name-fixed.appspot.com/

Errors

ERROR: (gcloud.app.deploy) An error occurred while parsing file: [/home/project/domain_name-server/app.yaml]
Unknown url handler type.
<URLMap
    secure=default
    static_files=None
    application_readable=None
    auth_fail_action=redirect
    require_matching_file=None
    static_dir=None
    redirect_http_response_code=None
    http_headers={u'Access-Control-Allow-Origin': 'https://domain_name-fixed.appspot.com/'}
    url=/.*
    script=None
    upload=None
    api_endpoint=None
    expiration=None
    position=None
    login=optional
    mime_type=None
    >
  in "/home/project/domain_name-server/app.yaml", line 10, column 73

nodejs cors settings

let cors = require("cors")

let origin =
    [
        "http://localhost:8080",
        `http://${ip.address()}:8080`,
        "http://localhost:4000",
        `http://${ip.address()}:4000`,
        "https://domain_name-fixed.appspot.com/"
    ]

app.use(cors({
    origin,
    credentials: true
}))

Upvotes: 4

Views: 704

Answers (1)

Cloud Ace Wenyuan Jiang
Cloud Ace Wenyuan Jiang

Reputation: 2205

You can only set HTTP headers for static files. You need to do the CORS part in nodejs code.

Upvotes: 3

Related Questions