📜  cors python 函数框架本地 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:03.192000             🧑  作者: Mango

代码示例2
def the_function(request):
    # Return CORS headers on OPTIONS request.
    if request.method == 'OPTIONS':
        headers = {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'GET',
            'Access-Control-Allow-Headers': 'Content-Type',
            'Access-Control-Max-Age': '3600'
        }
        return ('', 204, headers)
    
    # If the request is GET then handle it normally
    if request.method == 'GET':
        x = request.args('x')
        y = request.args('x')
        result = int(x) * int(y)
        headers = {
            'Access-Control-Allow-Origin': '*'
        }
        return (result, 200, headers)
     else:
        # If the request is not GET or OPTIONS, deny.
        return '', 400