diff --git a/.gitignore b/.gitignore index f23f47ea..6612b7cb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ web/po/vue.pot web_api/session/ web_api/public/ -web_api/static/ +web_api/static/node_modules web/static/.webassets-cache/ web/static/gen/ diff --git a/osmose.py b/osmose.py index abbb5ab4..0601390e 100644 --- a/osmose.py +++ b/osmose.py @@ -1,6 +1,7 @@ import os from fastapi import Depends, FastAPI, HTTPException, Request, Response, responses +from fastapi.middleware.cors import CORSMiddleware from api import app as api from control import app as control @@ -10,7 +11,21 @@ from web_api import app as web_api app = FastAPI() - +assets = FastAPI() + +assets.add_middleware( + CORSMiddleware, + allow_origins=[ + "https://osmose.openstreetmap.fr", + "http://localhost", + "http://localhost:8080", + "http://127.0.0.1", + "http://127.0.0.1:8080", + ], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) @app.on_event("startup") async def startup(): @@ -31,6 +46,8 @@ async def startup(): app.mount("/" + lang, web_api.app) +app.mount('/assets', assets) + @app.get("/") @app.get("/map") @app.get("/map/") @@ -44,7 +61,7 @@ def index(request: Request, langs: LangsNegociation = Depends(langs.langs)): return responses.RedirectResponse(url=path) -@app.get("/assets/sprites.css") +@assets.get("/sprites.css") def sprites_css(): file_path = "web_api/public/assets/sprites.css" if os.path.isfile(file_path): @@ -53,11 +70,21 @@ def sprites_css(): raise HTTPException(status_code=404) -@app.get("/assets/sprite.png") +@assets.get("/sprite.png") def sprite_png(): return Response(open("web_api/public/assets/sprite.png", "rb").read()) +@assets.get("/marker-gl-sprite.json") +def sprite_png(): + return Response(open("web_api/public/assets/marker-gl-sprite.json", "rb").read()) + + +@assets.get("/marker-gl-sprite.png") +def sprite_png(): + return Response(open("web_api/public/assets/marker-gl-sprite.png", "rb").read()) + + @app.get("/images/markers/{filename:path}.png") def marker(filename): file_path = f"web_api/static/images/markers/{filename}.png" @@ -72,4 +99,4 @@ async def catch_all(path_name: str): if os.path.isfile(file_path): return Response(open(file_path, "rb").read()) else: - raise HTTPException(status_code=404) + raise HTTPException(status_code=404) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 94b99817..20f8daeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ matplotlib >= 1.1 requests >= 2.0 polib protobuf < 4 # 4.x binary not yet compatible with system package, deps of mapbox-vector-tile +shapely < 2.1.0 # cascaded_union function removal, deps of mapbox-vector-tile mapbox-vector-tile pyclipper fastapi diff --git a/web/static/map/layers.ts b/web/static/map/layers.ts index 2bfbfda7..59032bf5 100644 --- a/web/static/map/layers.ts +++ b/web/static/map/layers.ts @@ -1,5 +1,7 @@ import { SourceSpecification } from 'maplibre-gl' +declare var API_URL: string; + function tileSource(url, options?): SourceSpecification { return { type: 'raster', @@ -98,8 +100,6 @@ export const mapOverlay = { heatmap: 'Osmose Issues Heatmap', } -const API_URL = 'https://osmose.openstreetmap.fr' - export const glStyle = { version: 8, sources: { diff --git a/web/types/index.d.ts b/web/types/index.d.ts deleted file mode 100644 index 6940f915..00000000 --- a/web/types/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare global { - var API_URL: string -} - -export { } diff --git a/web_api/static/webpack.config.js b/web_api/static/webpack.config.js index 0e156b8b..ad0aac07 100644 --- a/web_api/static/webpack.config.js +++ b/web_api/static/webpack.config.js @@ -10,7 +10,7 @@ module.exports = (env, argv) => { }, plugins: [ new SpritezeroWebpackPlugin({ - source: '../web_api/static/images/**/*.svg', + source: 'images/**/*.svg', output: 'marker-gl-', }) ],