File size: 966 Bytes
1e71909
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from fastapi import FastAPI, HTTPException
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

# Add CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

COG_DIRECTORY = "/data/cogs"

@app.get("/")
async def root():
    return {"message": "Welcome to the COG Server"}

@app.get("/cogs")
async def list_cogs():
    cogs = [f for f in os.listdir(COG_DIRECTORY) if f.endswith('.tif')]
    return {"cogs": cogs}

@app.get("/cogs/{cog_name}")
async def get_cog(cog_name: str):
    file_path = os.path.join(COG_DIRECTORY, cog_name)
    if not os.path.exists(file_path):
        raise HTTPException(status_code=404, detail="COG not found")
    return FileResponse(file_path, media_type="image/tiff")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)