Merge pull request #4 from mislavcimpersak/hotfix/deploy_stage

Hotfix/deploy stage
This commit is contained in:
Mislav Cimperšak 2017-10-15 16:38:18 +02:00 committed by GitHub
commit e5c23872a4
3 changed files with 17 additions and 9 deletions

View File

@ -22,7 +22,7 @@ Send `who`, `why` and `what` with desired text as GET parameters to `/v1/excuse`
Example:
```
https://xzmc1m2dgb.execute-api.eu-central-1.amazonaws.com/prod/v1/excuse/?who=serverless%20dev&why=my%20function%20is%20uploading%20to%20aws&what=uploading
https://tyiz03gx7h.execute-api.eu-central-1.amazonaws.com/prod/v1/excuse/?who=0&why=my%20code%20is%20compiling&what=compiling
```
You get the simplest api response in the world:
@ -30,7 +30,7 @@ You get the simplest api response in the world:
```
{
data: {
image_url: "http://localhost:8000/media/5345525645524c45535320444556-4d592046554e4354494f4e2049532055504c4f4144494e4720544f20415753-55504c4f4144494e47.png"
image_url: "https://tyiz03gx7h.execute-api.eu-central-1.amazonaws.com/media/30-4d5920434f444520495320434f4d50494c494e47-434f4d50494c494e47.png"
}
}
```

12
app.py
View File

@ -26,8 +26,8 @@ dir_path = os.path.dirname(os.path.realpath(__file__))
@hug.get(
versions=1,
examples='who=programmer&why=my%code%20is%20compiling&what=compiling'
versions=1
# examples='who=programmer&why=my%20code%20is%20compiling&what=compiling' TODO
)
def excuse(request, response, who: hug.types.text='', why: hug.types.text='', what: hug.types.text='') -> dict:
"""
@ -64,9 +64,11 @@ def excuse(request, response, who: hug.types.text='', why: hug.types.text='', wh
if isinstance(data, Image.Image):
who_hex, why_hex, what_hex = _encode_hex(who, why, what)
image_url = '{scheme}://{domain}/media/{who}-{why}-{what}.png'.format(
deploy_stage = os.environ.get('DEPLOY_STAGE')
image_url = '{scheme}://{domain}/{deploy_stage}media/{who}-{why}-{what}.png'.format(
scheme=request.scheme,
domain=request.netloc,
deploy_stage='{}/'.format(deploy_stage) if deploy_stage else '',
who=who_hex,
why=why_hex,
what=what_hex
@ -86,8 +88,8 @@ def excuse(request, response, who: hug.types.text='', why: hug.types.text='', wh
@hug.local()
@hug.get(
'/media/{who_hex}-{why_hex}-{what_hex}.png',
output=hug.output_format.png_image,
examples='/'
output=hug.output_format.png_image
# examples='/' TODO
)
def img(who_hex: hug.types.text, why_hex: hug.types.text, what_hex: hug.types.text):
"""

View File

@ -3,10 +3,16 @@
"app_function": "app.__hug_wsgi__",
"aws_region": "eu-central-1",
"profile_name": "mislavcimpersak",
"s3_bucket": "excuse-generator"
"s3_bucket": "excuse-generator",
"aws_environment_variables": {
"DEPLOY_STAGE": "prod"
}
},
"dev": {
"extends": "prod",
"debug": true
"debug": true,
"aws_environment_variables": {
"DEPLOY_STAGE": "dev"
}
}
}