11"""Microsoft Azure Function."""
22
33import azure .functions as func
4- from fastapi import FastAPI
5- from starlette .middleware .cors import CORSMiddleware
6- from starlette .requests import Request
7- from starlette .responses import HTMLResponse
8- from starlette_cramjam .middleware import CompressionMiddleware
9-
10- from titiler .application import __version__ as titiler_version
11- from titiler .application .main import cog , mosaic , stac , templates , tms
12- from titiler .application .settings import ApiSettings
13- from titiler .core .errors import DEFAULT_STATUS_CODES , add_exception_handlers
14- from titiler .core .middleware import (
15- CacheControlMiddleware ,
16- LoggerMiddleware ,
17- LowerCaseQueryStringMiddleware ,
18- TotalTimeMiddleware ,
19- )
20- from titiler .mosaic .errors import MOSAIC_STATUS_CODES
21-
22- api_settings = ApiSettings ()
23-
24- app = FastAPI (
25- title = api_settings .name ,
26- description = "A lightweight Cloud Optimized GeoTIFF tile server" ,
27- version = titiler_version ,
28- root_path = api_settings .root_path ,
29- )
30-
31- if not api_settings .disable_cog :
32- app .include_router (cog .router , prefix = "/cog" , tags = ["Cloud Optimized GeoTIFF" ])
33-
34- if not api_settings .disable_stac :
35- app .include_router (
36- stac .router , prefix = "/stac" , tags = ["SpatioTemporal Asset Catalog" ]
37- )
38-
39- if not api_settings .disable_mosaic :
40- app .include_router (mosaic .router , prefix = "/mosaicjson" , tags = ["MosaicJSON" ])
41-
42- app .include_router (tms .router , tags = ["TileMatrixSets" ])
43- add_exception_handlers (app , DEFAULT_STATUS_CODES )
44- add_exception_handlers (app , MOSAIC_STATUS_CODES )
45-
46-
47- # Set all CORS enabled origins
48- if api_settings .cors_origins :
49- app .add_middleware (
50- CORSMiddleware ,
51- allow_origins = api_settings .cors_origins ,
52- allow_credentials = True ,
53- allow_methods = ["GET" ],
54- allow_headers = ["*" ],
55- )
56-
57- app .add_middleware (
58- CompressionMiddleware ,
59- minimum_size = 0 ,
60- exclude_mediatype = {
61- "image/jpeg" ,
62- "image/jpg" ,
63- "image/png" ,
64- "image/jp2" ,
65- "image/webp" ,
66- },
67- )
68-
69- app .add_middleware (
70- CacheControlMiddleware ,
71- cachecontrol = api_settings .cachecontrol ,
72- exclude_path = {r"/healthz" },
73- )
74-
75- if api_settings .debug :
76- app .add_middleware (LoggerMiddleware , headers = True , querystrings = True )
77- app .add_middleware (TotalTimeMiddleware )
78-
79- if api_settings .lower_case_query_parameters :
80- app .add_middleware (LowerCaseQueryStringMiddleware )
81-
82-
83- @app .get ("/healthz" , description = "Health Check" , tags = ["Health Check" ])
84- def ping ():
85- """Health check."""
86- return {"ping" : "pong!" }
87-
88-
89- @app .get ("/" , response_class = HTMLResponse , include_in_schema = False )
90- def landing (request : Request ):
91- """TiTiler Landing page"""
92- return templates .TemplateResponse (
93- name = "index.html" ,
94- context = {"request" : request },
95- media_type = "text/html" ,
96- )
4+ from titiler .application .main import app
975
986
997async def main (
1008 req : func .HttpRequest ,
1019 context : func .Context ,
10210) -> func .HttpResponse :
10311 """Run App in AsgiMiddleware."""
104- return await func .AsgiMiddleware (app ).handle_async (req , context )
12+ return await func .AsgiMiddleware (app ).handle_async (req , context )
0 commit comments