Redirect to a URL functionality in Chalice
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.
Are you using a proxy? https://blog.rowanudell.com/redirects-in-serverless/
@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?
Why not return a chalice response object with status code 301 as in this project? https://github.com/skipluck/url-shortener-chalice
@areeves87 Thanks a ton! Exactly what I was looking for. :)