
本文共 4520 字,大约阅读时间需要 15 分钟。
���������������������������������
������������ Cross-Origin Request���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������
������������������������������������������
http://
��� https://
���www.baidu.com
��� baidu.com
���8080
��� 80
���������������������������������������������������������������������������������
������������������������
���������������������������������������������������������������������������
1. ���������������������������������������
��������������������������������������������������������������� CORS
��� Codix
������������������������������������������������������������������������
���������������������������������������������
module.exports = { publicPath: './', devServer: { proxy: { '/api': { target: 'http://backend-server.com', changeOrigin: true } } }}
������������������������������������������������������������������������������
��������������������� ������������������������������������������������������������ Access-Control-Allow-Origin
���Access-Control-Allow-Methods
��� Access-Control-Allow-Headers
���
������ extraordinaires headers��� ���������������������������������������������������������������������������������������������������������������
const headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE', 'Access-Control-Allow-Headers': 'Content-Type, Authorization'};this.$axios.defaults.headers.common = headers;
��������������� ������ frontend ��� backend ���������������������������)CORS
]));
2. ������������_Write
��������������������������������������������������������� File Writers API������������������������������������������������������������������������
const file = new Blob([/* ������������������ */], { type: 'text/plain' });file.write(name => `${name}.txt`);
������������������������������������������������������������������������������������������������������������
3. ������ WebSocket
- WebSocket ������������������������������������������������������������������������������������������ WebSocket Tunnel ������������������������
������������ frontend ������ WebSocket ���������
var ws = new WebSocket('ws://backend-server.com:8080');ws.onmessage = function (event) { console.log('������������:', event.data);};
������ backend ������ WebSocket ������������������������������������������
������������������������
������������������������������������������������������������������������������������������������������
���������������������forward proxy
��������� API ���������������������������������������������
curl -v -X OPTIONS http://yourdomain.com/api \--header "Host: your_backend_domain.com"
������������������ CORS ������������������������������������������������
������CDN
������������������������������������ URL ������������������ CDN ���������������������������������
������������������
������������������ CORS ���������������������������������������
# Apache ������Header set Access-Control-Allow-Origin "https://your.frontend.com"
���������������������*
������������������ production servers ������������
������������������������������������
������������������������������������������������������
���������������������������������������������������������������������������������
������������������ CORS ��������������������������� origin
������������������������������������������������������������ headers.
������������������������X-Frame-Options
������������������������ iframeocyte ��������� clickjacking���
������������������������������
���������������������������������������������������������������
curl -H "Origin: http://localhost:8080" \ -X POST http://localhost:8081/api/test \ -H "Content-Type: application/json" \ -d '{"method":"GET"}'
������ Command Line Tool ���������������������������������������������
������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
