在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):detailyang/lua-resty-cors开源软件地址(OpenSource Url):https://github.com/detailyang/lua-resty-cors开源编程语言(OpenSource Language):Lua 94.8%开源软件介绍(OpenSource Introduction):Namelua-resty-cors lua-resty-corsIt's the implement of CORS on OpenResty and It backports the nginx-http-cors to OpenResty Table of ContentsStatusUsageIt may be placed on the nginx http block for a global CORS config or in each server block to configure a different CORS for each virtual host as the following: http {
init_by_lua_block {
local cors = require('lib.resty.cors');
cors.allow_host([==[.*\.google\.com]==])
cors.allow_host([==[.*\.facebook\.com]==])
cors.expose_header('x-custom-field1')
cors.expose_header('x-custom-field2')
cors.allow_method('GET')
cors.allow_method('POST')
cors.allow_method('PUT')
cors.allow_method('DELETE')
cors.allow_header('x-custom-field1')
cors.allow_header('x-custom-field2')
cors.max_age(7200)
cors.allow_credentials(false)
}
header_filter_by_lua_block {
local cors = require('lib.resty.cors');
cors.run()
}
} APIallow_host
This will match the host from cors request then be added to the header Access-Control-Allow-Origin like as the following: Request:
Origin: https://www.google.com
Response:
Access-Control-Allow-Origin: http://www.google.com expose_header
This will be added to the header Access-Control-Expose-Headers like as the following: Request:
Origin: https://www.google.com
Response:
Access-Control-Expose-Headers: x-custom-field1,x-custom-field2 allow_method
This will be added to the header Access-Control-Allow-Methods like as the following: Request:
Origin: https://www.google.com
Response:
Access-Control-Allow-Methods:GET,POST,PUT allow_header
This will be added to the header Access-Control-Allow-Headers like as the following: Request:
Origin: https://www.google.com
Response:
Access-Control-Allow-Headers:x-custom-field1,x-custom-field2 max_age
This will be added to the header Access-Control-Max-Age like as the following: Request:
Origin: https://www.google.com
Response:
Access-Control-Max-Age: 7200 Allow-Credentials
This will be added to the header Access-Control-Allow-Credentials like as the following: Request:
Origin: https://www.google.com
Response:
Access-Control-Allow-Credentials: true run
This is the entry for lua-resty-cors to run ContributingTo contribute to lua-resty-cors, clone this repo locally and commit your code on a separate branch. PS: PR Welcome |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论