Jiang-Xuan / tuchuang.space

一个测试驱动的开源图床系统
https://tuchuang.space
MIT License
5 stars 1 forks source link

允许跨域的 DELETE 请求方法 #83

Closed Jiang-Xuan closed 4 years ago

Jiang-Xuan commented 4 years ago

2020.3.25 更新, 这里存在错误,post, get, options 等应该是大写 见 #91


删除图片的请求为 DELETE https://beta.tuchuang.space/api/v1/images

如果是跨域的 DELETE 请求, 目前返回的跨域请求头为:

Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: post, get, options
Access-Control-Allow-Origin: *

需要添加 DELETE 来允许跨域的 DELETE 请求:

Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: post, get, options, delete
Access-Control-Allow-Origin: *
Jiang-Xuan commented 4 years ago

如何测试

const response = await request(app)
  .options('/api/v1/images')

    expect(response.header['access-control-allow-methods']).toEqual('post, get, options, delete')
    expect(response.header['access-control-allow-origin']).toEqual('*')
    expect(response.header['access-control-allow-headers']).toEqual('*')