Avoid Having To Use CORS Or x-google-endpoints In Cloud Endpoints?

So I am having a very frustrating problem that I have been trying to solve for 2 days. I am not able to create a second version of our API because in order to call my cloud run endpoints cors needs to be set in GCP Cloud Endpoints like so:

x-google-endpoints:
  - name: gateway-url
    allowCors: true

However I cannot deploy this to two separate endpoint files, for example:

Version 1

swagger: '2.0'
host: gateway-url
x-google-endpoints:
  - name: gateway-url
    allowCors: true
info:
  title: Title
  description: Description
  version: 1.0.0
schemes:
  - https
produces:
  - application/json
consumes:
  - application/json
basePath: /v1

Version 2

swagger: '2.0'
host: gateway-url
x-google-endpoints:
  - name: gateway-url
    allowCors: true
info:
  title: Title
  description: Description
  version: 1.0.0
schemes:
  - https
produces:
  - application/json
consumes:
  - application/json
basePath: /v2

As you can see above I have 2 gateway files and I create a different gateway file for each version. However when I create anything more than a single cloud endpoints file I get the following error:

OpenAPI spec is invalid. Multiple endpoint entries are defined in the extension 'x-google-endpoints'. At most one entry is allowed.

I have tried many different things including taking the x-google-endpoints code out of my Endpoints file but when I do I lose control over CORS and can no longer handle it in cloud run.

My original cloud run file looked like this:

const express = require('express');
const router  = express.Router();
const routes = require('./routes');
const cors = require('cors');

const corsOptions = {
    origin: '*',
}

router.options('/', cors(corsOptions));

...

This did not work. Even after completely removing CORS from my Cloud Run service and trying to manually handle it like this:

app.use((req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization');
    if (req.method === 'OPTIONS') {
        return res.status(204).send('');
    }
    next();
});

I was still not able to call the endpoint. I have even tried adding options requests to the cloud endpoints YAML file and this still does not work.

options:
  summary: CORS Preflight
  description: Handle CORS preflight requests
  operationId: cors_preflight
  x-google-backend:
    address: https://my-cloud-run-service
  responses:
    '204':
      description: No Content

So my question is, is there any way to either:

  1. Handle CORS without using x-google-endpoints in the Endpoints YAML file?
  2. Handle CORS in my cloud run service without having to set it in Endpoints?
  3. Something else that Im missing that will easily get me past this?

BTW, I do know that a similar question was asked in 2019 here, But it was never really answered.

Using x-google-endpoints OpenAPI extension with multiple API versions in Cloud Endpoints

I cannot see versioning an API to be a niche use case and for this not to be handled is pretty counterintuitive on Googles side, so Im sure I have to be missing something. Any help with this would be greatly appreciated. Thanks.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật