AMP Access Control Allow Source Origin header Issue

前端 未结 3 531
北荒
北荒 2020-12-09 22:38

How can I resolve the error below;

Failed to load resource: the server responded with a status of 500 (Internal Server Error) cdn.ampproject.org/v0.

3条回答
  •  忘掉有多难
    2020-12-09 23:18

    Although OP uses PHP, I'm posting here for my javascript peeps.

    For node express server, you can use amp-toolbox-cors, which provides middleware.

    const express = require('express');
    const ampCors = require('amp-toolbox-cors');
    
    const app = express();
    
    // That's it!
    app.use(ampCors());
    ...
    

    By default, the AMP CORS middleware will only allow requests from AMP Caches listed on https://cdn.ampproject.org/caches.json (with the addition of bing-amp.com).

    All other origins will receive a 403 response.

    So for localhost or dev testing, you guys will probably want to also add the following:

    app.use(ampCors({
      verifyOrigin: false
    }));
    

    For those who want to take a deeper dive, here's a link to offical docs on how to comply with AMP CORS.

提交回复
热议问题