+ middleware = []
+ if config.get_bool('CORS_NOACCESSCONTROL'):
+ middleware.append(Middleware(CORSMiddleware,
+ allow_origins=['*'],
+ allow_methods=['GET', 'OPTIONS'],
+ max_age=86400))
+
+ log_file = config.LOG_FILE
+ if log_file:
+ middleware.append(Middleware(FileLoggingMiddleware, file_name=log_file))
+
+ exceptions: Dict[Any, Callable[[Request, Exception], Awaitable[Response]]] = {
+ TimeoutError: timeout_error
+ }
+
+ async def _shutdown() -> None:
+ await app.state.API.close()
+
+ app = Starlette(debug=debug, routes=routes, middleware=middleware,
+ exception_handlers=exceptions,
+ on_shutdown=[_shutdown])
+
+ app.state.API = NominatimAPIAsync(project_dir, environ)