使用CNAME的DNS将Angular应用部署到Google云端存储时出现401错误

时间:2019-04-04 14:57:20

标签: angularjs angular google-cloud-platform cors google-cloud-storage

我正在尝试将有角度的应用程序部署到Google Cloud Storage存储桶,以便可以从那里提供应用程序。该存储桶具有公共访问权限,并且具有名称,以便我可以通过CNAME将其用作自定义网站(例如test.example.com)。该存储桶还配置为将主页映射到index.html,将404处理程序映射到index.html

在加载https://test.example.com时,大多数应用程序都可以很好地加载,但是通过XHR(GET中的/assets/)加载的任何资产都会出现HTTP 401错误。没有印前检查要求。我尝试设置CORS settings on the bucket的各种排列,但似乎无济于事。配置的一个非限制性示例是:

[
  {
    "origin": ["*"],
    "responseHeader": ["Accept", "Accept-Encoding", "Accept-Language", "Origin" , "Authorization", "Content-Type", "Content-Length", "user-agent", "referer", "cookie"],
    "method": ["GET", "POST", "PUT", "HEAD", "DELETE"],
    "maxAgeSeconds": 3600
  }
]

如果我像XHR请求那样卷曲资产并设置Origin标头,则会得到我希望可以使XHR工作的标头(特别是access-control-allow-originaccess-control-expose-headers ):

➜  ~ curl -H "Origin: https://test.example.com" -I https://storage.googleapis.com/test.example.com/assets/icons/baseline-add_circle-24px.svg 
HTTP/2 200 
x-guploader-uploadid: AEnB2UqlMyfGJ4gfyQJUTL2CW7E7FU2UXUrRguYn4fSZUrP0DBVt0OwCUBhEGcvUR1OGiFSU7__Ui5IKHv6qeaLQhZmC-ChsMg
expires: Thu, 04 Apr 2019 14:53:32 GMT
date: Thu, 04 Apr 2019 14:53:32 GMT
cache-control: private, max-age=0
last-modified: Fri, 22 Mar 2019 16:06:05 GMT
etag: "121fb69a596fe32f1e77c4dec1c6ac35"
x-goog-generation: 1553270765793354
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 238
x-goog-meta-goog-reserved-file-mtime: 1553270763
content-type: image/svg+xml
x-goog-hash: crc32c=s8OcMw==
x-goog-hash: md5=Eh+2mllv4y8ed8TewcasNQ==
x-goog-storage-class: MULTI_REGIONAL
accept-ranges: bytes
content-length: 238
access-control-allow-origin: *
access-control-expose-headers: Accept, Accept-Encoding, Accept-Language, Authorization, Content-Length, Content-Type, Date, Origin, Server, Transfer-Encoding, X-GUploader-UploadID, X-Google-Trace, cookie, referer, user-agent
server: UploadServer
alt-svc: quic=":443"; ma=2592000; v="46,44,43,39"

如果像我希望浏览器那样对CNAME的DNS发出请求,我也会看到我期望的东西:

HTTP/2 200 
date: Thu, 04 Apr 2019 16:40:36 GMT
content-type: image/svg+xml
content-length: 238
set-cookie: __cfduid=dfbe3886fec0acb8dc6284c08950ca0621554396036; expires=Fri, 03-Apr-20 16:40:36 GMT; path=/; domain=.gotponcho.dev; HttpOnly; Secure
x-guploader-uploadid: AEnB2Ur6g3DmXzRA9l5I9IHFrBpgLD0Yx6CsNrxjouI2_zXp0B5v6quBO85M-um0bPp0SQU4lnTyLCryKkf3aNbFpVl-W76BpUarlNqS6BOAjyNzIhN-kf4
expires: Thu, 04 Apr 2019 20:40:36 GMT
cache-control: public, max-age=14400
last-modified: Fri, 22 Mar 2019 16:06:05 GMT
etag: "121fb69a596fe32f1e77c4dec1c6ac35"
x-goog-generation: 1553270765793354
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 238
x-goog-meta-goog-reserved-file-mtime: 1553270763
x-goog-hash: crc32c=s8OcMw==
x-goog-hash: md5=Eh+2mllv4y8ed8TewcasNQ==
x-goog-storage-class: MULTI_REGIONAL
access-control-allow-origin: *
access-control-expose-headers: Accept, Accept-Encoding, Accept-Language, Authorization, Content-Length, Content-Type, Date, Origin, Server, Transfer-Encoding, X-GUploader-UploadID, X-Google-Trace, cookie, referer, user-agent, x-concept-id, x-location-id
cf-cache-status: MISS
accept-ranges: bytes
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4c24b99abc6cc7bf-DEN

还有其他需要使Angular可以在Google Cloud Storage上运行吗?

0 个答案:

没有答案