Last active
May 6, 2020 10:39
-
-
Save sk-t3ch/a672dba1892160e9d5bc1806fa0ce224 to your computer and use it in GitHub Desktop.
Hello World Cluster CloudFormation - Python Web Server with CORS enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiohttp import web | |
import aiohttp_cors | |
import json | |
async def healthcheck(_): | |
headers = { | |
"Cache-Control": "no-cache, no-store, must-revalidate", | |
"Pragma": "no-cache", | |
"Expires": "0", | |
} | |
return web.Response(text=json.dumps("Healthy"), headers=headers, status=200) | |
async def helloworld(_): | |
return web.Response(text="<h1>HELLO WORLD</h1>", content_type='text/html', status=200) | |
app = web.Application() | |
cors = aiohttp_cors.setup(app) | |
app.router.add_get("/healthcheck", healthcheck) | |
app.router.add_get("/", helloworld) | |
cors = aiohttp_cors.setup(app, defaults={ | |
"*": aiohttp_cors.ResourceOptions( | |
allow_credentials=True, | |
expose_headers="*", | |
allow_headers="*", | |
) | |
}) | |
# Configure CORS on all routes. | |
for route in list(app.router.routes()): | |
cors.add(route) | |
if __name__ == "__main__": | |
print("Starting service") | |
web.run_app(app, host="0.0.0.0", port=(5000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment