Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
28 changes: 28 additions & 0 deletions osmose.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,23 @@

app = FastAPI()

origins = [
Copy link
Contributor

@frodrigo frodrigo Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORS on non public API are on purpose.

I'm OK for CORS as middleware, but only for API. Host can be *.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may find more appropriate strategy for origins (I choose the default one).
But I was unable to get https://osmose.openstreetmap.fr/assets/marker-gl-sprite.png from localhost:8080 when opening the map in my browser.

localhost should rely on localhost resources only and we may adjust appropriate origins depending on env prod/dev

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed @frodrigo, I didn't understand properly the nesting with FastAPI.

I've specified more appropriate CORS for web assets only, and preserving the existing CORS for everything else.

"https://osmose.openstreetmap.fr",
"http://localhost",
"http://localhost:8080",
"http://localhost:20009",
"http://127.0.0.1",
"http://127.0.0.1:8080",
"http://127.0.0.1:20009"
]

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

@app.on_event("startup")
async def startup():
Expand Down Expand Up @@ -58,6 +76,16 @@ def sprite_png():
return Response(open("web_api/public/assets/sprite.png", "rb").read())


@app.get("/assets/marker-gl-sprite.json")
def sprite_png():
return Response(open("web_api/public/assets/marker-gl-sprite.json", "rb").read())


@app.get("/assets/marker-gl-sprite.png")
def sprite_png():
return Response(open("web_api/public/assets/marker-gl-sprite.png", "rb").read())


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May just implement it in a generic way in the catch_all ?

Copy link
Contributor Author

@flacombe flacombe Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch_all is rooted in web/public and assets are in web_api.

Routing appropriate resources between web/public and web_api in catch_all is equivalent to define dedicated routes

I wondered how these resources are served today and didn't found out

@app.get("/images/markers/{filename:path}.png")
def marker(filename):
file_path = f"web_api/static/images/markers/{filename}.png"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions web/static/map/layers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { SourceSpecification } from 'maplibre-gl'

declare var API_URL: string;

function tileSource(url, options?): SourceSpecification {
return {
type: 'raster',
Expand Down Expand Up @@ -98,8 +100,6 @@ export const mapOverlay = {
heatmap: 'Osmose Issues Heatmap',
}

const API_URL = 'https://osmose.openstreetmap.fr'

export const glStyle = {
version: 8,
sources: {
Expand Down
5 changes: 0 additions & 5 deletions web/types/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion web_api/static/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (env, argv) => {
},
plugins: [
new SpritezeroWebpackPlugin({
source: '../web_api/static/images/**/*.svg',
source: 'images/**/*.svg',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May you need this, because you de not run it from the right path ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run this from the docker-compose, in the osmose-frontend/docker directory

docker-compose -f docker-compose.yml -f docker-compose-test.yml up

And it didn't work unless I make the path relative to the config file (which is already in web_api/static)

output: 'marker-gl-',
})
],
Expand Down