
一句话承诺:一张表+两段代码,快速打通简单跨域请求。

头 | 示例 | 说明 |
|---|---|---|
Access-Control-Allow-Origin | https://app.dev | 或 * |
Access-Control-Allow-Methods | GET,POST | 允许方法 |
Access-Control-Allow-Headers | Authorization | 自定义头 |
Access-Control-Allow-Credentials | true | 允许cookie |
app.use((req,res,next)=>{
res.header('Access-Control-Allow-Origin','https://app.dev');
res.header('Access-Control-Allow-Methods','GET,POST,PUT,DELETE');
res.header('Access-Control-Allow-Headers','Content-Type,Authorization');
res.header('Access-Control-Allow-Credentials','true');
if (req.method === 'OPTIONS') return res.sendStatus(204);
next();
});fetch('https://api.dev/data', {
method: 'GET',
credentials: 'include',
headers: { 'Authorization': 'Bearer xxx' }
});CDN 回源与缓存规则:Cache-Key 与回源时序(图+表)。