zl程序教程

您现在的位置是:首页 >  后端

当前栏目

跨域

2023-09-11 14:22:19 时间

#### jsonp

* 知识点补充

* url核心对象

* ```js
const url = require('url');
url.parse('http://xxx.com?id=1',true); // 第二个参数是将id=1转换成对象
// output: { protocal:'http',..省略..query:{id:1} }
```

* ​

#### CORS

* ```
Access-Control-Allow-Origin: 'http://xxx.com' //允许哪个域在跨域的时候访问,*代表所有
// 告诉浏览器,跨域时允许有cookie,同时客户端也要设置withCredentials:true + Origin不能是*
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: 'GET,POST,PUT,DELETE'; // 默认允许get/post
Access-Control-Allow-Headers:'xxx'; // 允许你自己加的头来通信
```

* 浏览器在非简单请求(get/post)||包含自定义头||content-type非键值对的时候,会先请示服务器,来一个OPTIONS请求,如果不满足,拒绝发送ajax请求

#### 代理

* 下载依赖包便于请求操作 ```npm i request -S```

#### nginx代理

* __操作最好在管理员权限下进行__
* nginx -s [opt] opt:stop, quit, reopen, reload


* 启动nginx: 命令行进入到解压目录 ```start nginx ```
* 查看nginx启动进程 ```tasklist /fi "imagename eq nginx.exe"```
* 关闭进程 ```nginx -s stop```