Skip to content

Commit

Permalink
Merge pull request #86 from pka/base-url
Browse files Browse the repository at this point in the history
Add support for URL prefix
  • Loading branch information
pka authored Nov 11, 2024
2 parents 3556745 + 020ff8d commit 5aad5c2
Show file tree
Hide file tree
Showing 28 changed files with 1,891 additions and 1,723 deletions.
8 changes: 7 additions & 1 deletion bbox-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ pub struct WebserverCfg {
pub server_addr: String,
/// Number of parallel web server threads. Defaults to number of available logical CPUs
worker_threads: Option<usize>,
public_server_url: Option<String>,
/// Public base URL of the server (e.g. `https://bbox.example.com/`)
pub public_server_url: Option<String>,
/// Log level (Default: info)
pub loglevel: Option<Loglevel>,
pub tls_cert: Option<String>,
Expand Down Expand Up @@ -172,6 +173,11 @@ impl CoreServiceCfg {
pub fn loglevel(&self) -> Option<Loglevel> {
self.webserver.as_ref().and_then(|cfg| cfg.loglevel.clone())
}
pub fn public_server_url(&self) -> Option<String> {
self.webserver
.as_ref()
.and_then(|cfg| cfg.public_server_url.clone())
}
}

impl Default for WebserverCfg {
Expand Down
124 changes: 67 additions & 57 deletions bbox-core/src/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.2
info:
title: 'BBOX OGC API'
title: "BBOX OGC API"
description: |-
OpenAPI definition that conforms to the conformance
classes "Core", "GeoJSON" and "OpenAPI 3.0" of the
Expand All @@ -9,14 +9,14 @@ info:
contact:
name: Acme Corporation
email: info@example.org
url: 'http://example.org/'
url: "http://example.org/"
# x-logo:
# url: 'https://www.ogc.org/pub/www/files/OGC_Logo_2D_Blue_x_0_0.png'
license:
name: CC-BY 4.0 license
url: 'https://creativecommons.org/licenses/by/4.0/'
url: "https://creativecommons.org/licenses/by/4.0/"
servers:
- url: 'http://bbox:8080/'
- url: "http://bbox:8080/"
description: Production server
# - url: 'http://host.docker.internal:8080/'
# description: Development server
Expand All @@ -27,13 +27,13 @@ paths:
"/":
get:
tags:
- Landing Page
- Landing Page
operationId: getLandingPage
summary: Retrieve the OGC API landing page for this service.
# parameters:
# - "$ref": "#/components/parameters/f-metadata"
responses:
'200':
"200":
description: |-
The landing page provides links to the API definition (link relation `service-desc`, in this case path `/api`),
to the Conformance declaration (path `/conformance`, link relation `conformance`), and to the Collections of geospatial data (path `/collections`, link relation `data`).
Expand All @@ -43,74 +43,76 @@ paths:
"$ref": "#/components/schemas/landingPage"
example:
title: Buildings in Bonn
description: Access to data about buildings in the city of Bonn via a
description:
Access to data about buildings in the city of Bonn via a
Web API that conforms to the OGC API Tiles specification.
links:
- href: http://data.example.org/
rel: self
type: application/json
title: this document
- href: http://data.example.org/api
rel: service-desc
type: application/vnd.oai.openapi+json;version=3.0
title: the API definition
- href: http://data.example.org/api.html
rel: service-doc
type: text/html
title: the API documentation
- href: http://data.example.org/conformance
rel: conformance
type: application/json
title: OGC API conformance classes implemented by this service
- href: http://data.example.org/collections
rel: data
type: application/json
title: Information about the collections
- href: http://data.example.org/
rel: self
type: application/json
title: this document
- href: http://data.example.org/api
rel: service-desc
type: application/vnd.oai.openapi+json;version=3.0
title: the API definition
- href: http://data.example.org/api.html
rel: service-doc
type: text/html
title: the API documentation
- href: http://data.example.org/conformance
rel: conformance
type: application/json
title: OGC API conformance classes implemented by this service
- href: http://data.example.org/collections
rel: data
type: application/json
title: Information about the collections
text/html:
schema:
type: string
'406':
"406":
"$ref": "#/components/responses/NotAcceptable"
'500':
"500":
"$ref": "#/components/responses/ServerError"
"/conformance":
get:
tags:
- Conformance
- Conformance
operationId: getConformanceDeclaration
summary: Retrieve the set of OGC API conformance classes that are supported
summary:
Retrieve the set of OGC API conformance classes that are supported
by this service.
# parameters:
# - "$ref": "#/components/parameters/f-metadata"
responses:
'200':
"200":
description: The URIs of all conformance classes supported by the server
content:
application/json:
schema:
allOf:
- "$ref": "#/components/schemas/confClasses"
- "$ref": "#/components/schemas/confClasses"
example:
conformsTo:
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/json
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/html
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/oas30
- http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections
'406':
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/json
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/html
- http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/oas30
- http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections
"406":
"$ref": "#/components/responses/NotAcceptable"
'500':
"500":
"$ref": "#/components/responses/ServerError"
"/openapi":
get:
tags:
- API
- API
operationId: getOpenapi
summary: Retrieve this API definition.
# parameters:
# - "$ref": "#/components/parameters/f-metadata"
responses:
'200':
"200":
description: The OpenAPI definition of the API.
content:
application/vnd.oai.openapi+json;version=3.0:
Expand All @@ -119,16 +121,16 @@ paths:
text/html:
schema:
type: string
'406':
"406":
"$ref": "#/components/responses/NotAcceptable"
'500':
"500":
"$ref": "#/components/responses/ServerError"
components:
schemas:
confClasses:
type: object
required:
- conformsTo
- conformsTo
properties:
conformsTo:
type: array
Expand All @@ -137,8 +139,8 @@ components:
link:
type: object
required:
- href
- rel
- href
- rel
properties:
href:
type: string
Expand All @@ -150,43 +152,49 @@ components:
example: alternate
type:
type: string
description: A hint indicating what the media type of the result of dereferencing
description:
A hint indicating what the media type of the result of dereferencing
the link should be.
example: application/geo+json
templated:
type: boolean
description: This flag set to true if the link is a URL template.
hreflang:
type: string
description: A hint indicating what the language of the result of dereferencing
description:
A hint indicating what the language of the result of dereferencing
the link should be.
example: en
title:
type: string
description: Used to label the destination of a link such that it can be
description:
Used to label the destination of a link such that it can be
used as a human-readable identifier.
example: Trierer Strasse 70, 53115 Bonn
length:
type: integer
landingPage:
type: object
required:
- links
- links
properties:
title:
type: string
title: The title of the API.
description: While a title is not required, implementors are strongly advised
description:
While a title is not required, implementors are strongly advised
to include one.
example: Buildings in Bonn
description:
type: string
example: Access to data about buildings in the city of Bonn via a Web API
example:
Access to data about buildings in the city of Bonn via a Web API
that conforms to the OGC API Common specification.
attribution:
type: string
title: attribution for the API
description: The `attribution` should be short and intended for presentation
description:
The `attribution` should be short and intended for presentation
to a user, for example, in a corner of a map. Parts of the text can be
links to other resources if additional information is needed. The string
can include HTML markup.
Expand All @@ -199,7 +207,7 @@ components:
description: JSON schema for exceptions based on RFC 7807
type: object
required:
- type
- type
properties:
type:
type: string
Expand All @@ -213,7 +221,8 @@ components:
type: string
responses:
NotFound:
description: The requested resource does not exist on the server. For example,
description:
The requested resource does not exist on the server. For example,
a path parameter had an incorrect value.
content:
application/json:
Expand All @@ -223,7 +232,8 @@ components:
schema:
type: string
NotAcceptable:
description: Content negotiation failed. For example, the `Accept` header submitted
description:
Content negotiation failed. For example, the `Accept` header submitted
in the request did not support any of the media types supported by the server
for the requested resource.
content:
Expand Down
2 changes: 1 addition & 1 deletion bbox-core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct CoreService {

impl CoreService {
pub fn add_service<T: OgcApiService>(&mut self, svc: &T) {
let api_base = "";
let api_base = self.web_config.public_server_url.as_deref().unwrap_or("");

self.ogcapi
.landing_page_links
Expand Down
9 changes: 5 additions & 4 deletions bbox-core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=devide-width, initial-scale=1.0" />
<title>BBOX - {% block title %}Home{% endblock %}</title>
<link href="/frontend/bbox.css" rel="stylesheet">
<base href="{{base_url | safe}}" />
<link href="frontend/bbox.css" rel="stylesheet">
<link href="https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet" />
{% block head %} {% endblock %}
</head>
Expand All @@ -29,12 +30,12 @@ <h2>{% block content_title %}{% endblock %}</h2>

<ul class="menu bg-base-200 w-56 h-full rounded-box">
<li>
<a href="/" {% if cur_menu=="Home" %}class="active" {% endif %}>
<a href="./" {% if cur_menu=="Home" %}class="active" {% endif %}>
<i class="bx bx-grid-alt"></i> Home
</a>
</li>
<li>
<a href="/collections" {% if cur_menu=="Collections" %}class="active" {% endif %}>
<a href="collections" {% if cur_menu=="Collections" %}class="active" {% endif %}>
<i class="bx bx-list-ul"></i> Collections
</a>
</li>
Expand All @@ -44,7 +45,7 @@ <h2>{% block content_title %}{% endblock %}</h2>
</a>
</li>
<li>
<a href="/redoc.html" {% if cur_menu=="API" %}class="active" {% endif %}>
<a href="redoc.html" {% if cur_menu=="API" %}class="active" {% endif %}>
<i class="bx bx-code-alt"></i> API
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion bbox-core/templates/collections.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<tbody>
{% for collection in collections.collections %}
<tr>
<td><a href="/collections/{{ collection.id }}">{{ collection.title }}</a></td>
<td><a href="collections/{{ collection.id }}">{{ collection.title }}</a></td>
<td>{{ collection.description }}</td>
</tr>
{% endfor %}
Expand Down
Loading

0 comments on commit 5aad5c2

Please sign in to comment.