Browse Source

Definició de la callback per als estatics del servidor

develop
orzo 7 months ago
parent
commit
969dc04304
  1. 1
      .gitignore
  2. 2
      client/public/index.html
  3. 32
      server/main.py
  4. 31
      server/public/index.html
  5. 5
      server/requirements.txt
  6. 10
      server/static/index.html
  7. 20
      server/wsgi.py

1
.gitignore vendored

@ -5,3 +5,4 @@ images
node_modules
__pycache__
log/*
server/public/*

2
client/public/index.html

@ -8,7 +8,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
<link rel="stylesheet" href="index.css">
<script src="vendor/vue.min.js"></script>
<script src="/public/vendor/vue.min.js"></script>
<title>Map</title>
</head>

32
server/main.py

@ -0,0 +1,32 @@
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("/public/",
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)

31
server/public/index.html

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
<link rel="stylesheet" href="/public/index.css">
<script src="/public/vendor/vue.min.js"></script>
<title>Map</title>
</head>
<body>
<div id="app"></div>
</body>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
<script src="/public/index.js"></script>
</html>

5
server/requirements.txt

@ -4,4 +4,7 @@ pypdf2
pyspellchecker
numpy
opencv-python
geocoder
geocoder
aiohttp
aiofiles
fastapi

10
server/static/index.html

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Desregistradores</title>
</head>
<body>
<h1>Desregistradores</h1>
</body>
</html>

20
server/wsgi.py

@ -1,20 +0,0 @@
import os
import asyncio
import aiohttp
import aiofiles
dir = os.path.dirname(__file__)
routes = aiohttp.RouteTableDef()
app = aiohttp.web.Application()
app.router.add_static("/static/",
path=os.path.join(dir, "static"),
name="static")
@routes.get("/")
async def index():
async with aiofiles.open(os.path.join(dir, "static", "index.html")) as conn:
return web.Response(text=conn.read(), content_type="text/html")
if __name__ == "__main__":
aiohttp.runapp(app)
Loading…
Cancel
Save