Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const client = new upyun.Client(service[, options][, getHeaderSignCallback])
- `options`: 配置项,可以配置以下参数
- `domain`: 又拍云 rest api 地址,默认 `v0.api.upyun.com` 其他可配置域名见又拍云[文档](http://docs.upyun.com/api/rest_api/)
- `protocol`: 使用 `http|https` 协议,默认 `https` 协议
- `proxy`: 代理配置见[使用说明](https://github.com/upyun/node-sdk/pull/63). 默认为 `undefined`.
- `getHeaderSignCallback`: 获取又拍云 HTTP Header 签名回调函数,服务端使用时不需要设置该参数。客户端使用必须设置该回调函数,它接受四个参数:`service, method, path, contentMD5`, 用于计算当前请求签名,其中 `contentMD5` 可选填。如果回调函数是异步,则必须返回一个 `Promise`

**示例**
Expand Down
3 changes: 2 additions & 1 deletion upyun/create-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ axios.defaults.adapter = (function () {
return http
})()

export default function (endpoint, service, getHeaderSign) {
export default function (endpoint, service, getHeaderSign, {proxy} = {}) {
const req = axios.create({
baseURL: endpoint + '/' + service.serviceName,
maxRedirects: 0,
proxy
})

req.interceptors.request.use((config) => {
Expand Down
12 changes: 8 additions & 4 deletions upyun/upyun.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ export default class Upyun {

const config = Object.assign({
domain: 'v0.api.upyun.com',
protocol: 'https'
protocol: 'https',
// proxy: false // 禁用代理 // 参考 axios 配置. 如: {host: '127.0.0.1', post: 1081}
}, params)
this.endpoint = config.protocol + '://' + config.domain

this.req = createReq(this.endpoint, service, getHeaderSign || defaultGetHeaderSign)
this.endpoint = config.protocol + '://' + config.domain
const {proxy} = config
this.proxy = proxy
this.req = createReq(this.endpoint, service, getHeaderSign || defaultGetHeaderSign, {proxy})
// NOTE this will be removed
this.bucket = service
this.service = service
Expand Down Expand Up @@ -461,7 +464,8 @@ export default class Upyun {
return axios.post(
'http://purge.upyun.com/purge/',
'purge=' + urls.join('\n'), {
headers
headers,
proxy: this.proxy
}
).then(({data}) => {
if (Object.keys(data.invalid_domain_of_url).length === 0) {
Expand Down