chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Redirect to a URL functionality in Chalice

Open rg666 opened this issue 5 years ago • 4 comments

Please add a redirect method in Chalice, which can help us to redirect to a different URL, just like we can use redirect() method in Flask.

rg666 avatar Jun 13 '21 12:06 rg666

Are you using a proxy? https://blog.rowanudell.com/redirects-in-serverless/

brno32 avatar Jun 13 '21 14:06 brno32

@brno32

No, actually I want to do an absolute URL redirection. I'm basically creating a url-shortener app as learning Chalice, I know and have used redirect() method in a flask app but I searched Chalice documentation I wasn't able to find a similar funtionality.

@app.route('/{id}', methods=['GET'])
def redirect(id):
    response = get_dynamo_db_table().query(
        KeyConditionExpression=Key("id").eq(id)
    )
    data = response.get('Items', None)
    redirect_url = data[0]['originalurl']
    return redirect_url
    # return redirect(redirect_url)

Here, for example I should be able to redirect the user to 'redirect_url'. Any thoughts?

rg666 avatar Jun 13 '21 15:06 rg666

Why not return a chalice response object with status code 301 as in this project? https://github.com/skipluck/url-shortener-chalice

areeves87 avatar Jun 13 '21 20:06 areeves87

@areeves87 Thanks a ton! Exactly what I was looking for. :)

rg666 avatar Jun 13 '21 20:06 rg666