diff --git a/services/home/app/config.py b/services/home/app/config.py index 2b510bb..fe947f7 100644 --- a/services/home/app/config.py +++ b/services/home/app/config.py @@ -1,7 +1,16 @@ import logging import os +base_url = 'https://demo.pygeoapi.io' + # local config, change on server for real config config = { 'loglevel': int(os.getenv('ADMIN_LOG_LEVEL', logging.DEBUG)) } + +services = [ + {'href': '/master', 'title': "pygeoapi - latest GitHub 'master' version"}, + {'href': '/stable', 'title': 'pygeoapi - latest stable version'}, + {'href': '/cite', 'title': "pygeoapi - CITE endpoint - latest GitHub 'master' version"}, # noqa + {'href': '/covid-19', 'title': "pygeoapi - COVID-19 endpoint - latest GitHub 'master' version"} # noqa +] diff --git a/services/home/app/index.py b/services/home/app/index.py index 54bf67a..9eccb5e 100644 --- a/services/home/app/index.py +++ b/services/home/app/index.py @@ -4,12 +4,13 @@ from datetime import datetime from functools import wraps, update_wrapper -from config import config +from config import base_url, config, services from flask import Flask, render_template, make_response, send_from_directory if __name__ != '__main__': - # When run with WSGI in Apache we need to extend the PYTHONPATH to find Python modules relative to index.py + # When run with WSGI in Apache we need to extend the PYTHONPATH + # to find Python modules relative to index.py sys.path.insert(0, os.path.dirname(__file__)) app = Flask(__name__) @@ -30,7 +31,7 @@ def nocache(view): def no_cache(*args, **kwargs): response = make_response(view(*args, **kwargs)) response.headers['Last-Modified'] = datetime.now() - response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0' + response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0' # noqa response.headers['Pragma'] = 'no-cache' response.headers['Expires'] = '-1' return response @@ -45,6 +46,37 @@ def home(): return page('home') +# API catalog +@app.route('/api-catalog.json') +@app.route('/.well-known/api-catalog') +@nocache +def api_catalog(): + response = { + 'linkset': [] + } + + for service in services: + url = f"{base_url}{service['href']}" + response['linkset'].append({ + 'anchor': url, + 'service-desc': [{ + 'href': f'{url}/openapi?f=json', + 'title': f"{service['title']} (JSON)", + 'type': 'application/vnd.oai.openapi+json' + }], + 'service-doc': [{ + 'href': f'{url}/openapi?f=html', + 'title': f"{service['title']} (HTML)", + 'type': 'text/html' + }], + }) + + r = make_response(response) + r.mimetype = 'application/linkset+json' + + return r + + # Specific page @app.route('/') @nocache @@ -69,12 +101,13 @@ def page(page_name): else: page_file = '%s%s' % (page_name, '.html') - result = render_template(page_file) - except Exception as e: + result = render_template(page_file, services=services) + except Exception: result = render_template('error.html'), 404 return result + if __name__ == '__main__': # Run as main via python index.py app.run(debug=True, host='0.0.0.0') diff --git a/services/home/app/templates/home.html b/services/home/app/templates/home.html index d4d338b..b5d9948 100644 --- a/services/home/app/templates/home.html +++ b/services/home/app/templates/home.html @@ -11,21 +11,16 @@

Welcome to pygeoapi Demo Server

- + + + {% for service in services %} - - - - - - - - - - + + {% endfor %} +
DemonstrationsDemonstrations (API Catalog)
pygeoapi - latest GitHub 'master' version
pygeoapi - latest stable version
pygeoapi - CITE endpoint - latest GitHub 'master' version
pygeoapi - COVID-19 endpoint - latest GitHub 'master' version{{ service['title'] }}
Test Client - by OpenGeoGroep