You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
942 B

import os
import asyncio
from aiohttp import web
import aiofiles
dir = os.path.dirname(__file__)
routes = web.RouteTableDef()
app = web.Application()
app.router.add_static("/",
path=os.path.join(dir, "public"),
name="public")
# @routes.get("/")
# async def index(request):
# async with aiofiles.open(os.path.join(dir, "public", "index.html")) as conn:
# return web.Response(text=await conn.read(), content_type="text/html")
@routes.get("/data/{resource}")
async def data(request):
# Obrir una conexió amb base de dates
# Fer la consulta que vulgui definia pels possibles paramatres de la url
file = request.match_info["resource"]
async with aiofiles.open(os.path.join(dir, "public", "data", file)) as conn:
return web.Response(text= await conn.read(), content_type="application/json")
app.add_routes(routes)
if __name__ == "__main__":
web.run_app(app)