mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-31 01:09:22 +02:00
make OSM API connection details configurable via env vars
This commit is contained in:
9
API.md
9
API.md
@@ -101,6 +101,15 @@ In addition, the following parameters are available as **URL query parameters**:
|
||||
* __`gpx`__ - Expects a trace ID of a [public gps trace](https://www.openstreetmap.org/traces) uploaded on OpenStreetMap.<br/>
|
||||
_Example:_ `https://www.openstreetmap.org/edit?editor=id&gpx=4009513`<br/>
|
||||
|
||||
|
||||
## Environment variables
|
||||
|
||||
Environment variables or a dotenv file can be used to configure certain aspects of iD at build time.
|
||||
|
||||
* __`ID_PRESETS_CDN_URL`__ - The URL where iD should fetch it's tagging presets from. Needs to point to a CORS enabled web server which is serving the `package.json` and `dist` folder of a repository built on [`@ideditor/schema-builder`](https://github.com/ideditor/schema-builder).
|
||||
* __`ID_API_CONNECTION_URL`__, __`ID_API_CONNECTION_CLIENT_ID`__, __`ID_API_CONNECTION_CLIENT_SECRET`__ - custom [Oauth2](https://wiki.openstreetmap.org/wiki/OAuth#OAuth_2.0_2) connection details to an OSM API server
|
||||
* __`ID_API_CONNECTION`__ - either `live` or `dev`, if only either one should be made offered for editing
|
||||
|
||||
## CSS selectors
|
||||
|
||||
iD has a documented and stable set of classes that can be used to apply style or
|
||||
|
||||
@@ -2,7 +2,11 @@ import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
const envs = {
|
||||
ENV__ID_PRESETS_CDN_URL: JSON.stringify(process.env.ID_PRESETS_CDN_URL || null)
|
||||
ENV__ID_PRESETS_CDN_URL: JSON.stringify(process.env.ID_PRESETS_CDN_URL || null),
|
||||
ENV__ID_API_CONNECTION_URL: JSON.stringify(process.env.ID_API_CONNECTION_URL || null),
|
||||
ENV__ID_API_CONNECTION_CLIENT_ID: JSON.stringify(process.env.ID_API_CONNECTION_CLIENT_ID || null),
|
||||
ENV__ID_API_CONNECTION_CLIENT_SECRET: JSON.stringify(process.env.ID_API_CONNECTION_CLIENT_SECRET || null),
|
||||
ENV__ID_API_CONNECTION: JSON.stringify(process.env.ID_API_CONNECTION || null)
|
||||
}
|
||||
|
||||
export default envs;
|
||||
|
||||
32
config/id.js
32
config/id.js
@@ -7,17 +7,41 @@ const wmfSitematrixCdnUrl = 'https://cdn.jsdelivr.net/npm/wmf-sitematrix@{versio
|
||||
const nsiCdnUrl = 'https://cdn.jsdelivr.net/npm/name-suggestion-index@{version}/';
|
||||
|
||||
// api urls and settings
|
||||
const osmApiConnections = [
|
||||
{ // "live" db
|
||||
const defaultOsmApiConnections = {
|
||||
"live": {
|
||||
url: 'https://www.openstreetmap.org',
|
||||
client_id: '0tmNTmd0Jo1dQp4AUmMBLtGiD9YpMuXzHefitcuVStc',
|
||||
client_secret: 'BTlNrNxIPitHdL4sP2clHw5KLoee9aKkA7dQbc0Bj7Q'
|
||||
}, { // "dev" db
|
||||
},
|
||||
"dev": {
|
||||
url: 'https://api06.dev.openstreetmap.org',
|
||||
client_id: 'Ee1wWJ6UlpERbF6BfTNOpwn0R8k_06mvMXdDUkeHMgw',
|
||||
client_secret: 'OnfWFC-JkZNHyYdr_viNn_h_RTZXRslKcUxllOXqf5g'
|
||||
}
|
||||
];
|
||||
};
|
||||
const osmApiConnections = [];
|
||||
if (ENV__ID_API_CONNECTION_URL !== null &&
|
||||
ENV__ID_API_CONNECTION_CLIENT_ID !== null &&
|
||||
ENV__ID_API_CONNECTION_CLIENT_SECRET !== null) {
|
||||
// user specified API Oauth2 connection details
|
||||
// see https://wiki.openstreetmap.org/wiki/OAuth#OAuth_2.0_2
|
||||
osmApiConnections.push({
|
||||
url: ENV__ID_API_CONNECTION_URL,
|
||||
client_id: ENV__ID_API_CONNECTION_CLIENT_ID,
|
||||
client_secret: ENV__ID_API_CONNECTION_CLIENT_SECRET
|
||||
});
|
||||
} else if (ENV__ID_API_CONNECTION !== null &&
|
||||
defaultOsmApiConnections[ENV__ID_API_CONNECTION] !== undefined) {
|
||||
// if environment variable ID_API_CONNECTION is either "live" or "dev":
|
||||
// only allow to connect to the respective OSM server
|
||||
osmApiConnections.push(defaultOsmApiConnections[ENV__ID_API_CONNECTION]);
|
||||
} else {
|
||||
// offer both "live" and "dev" servers by default
|
||||
osmApiConnections.push(defaultOsmApiConnections.live);
|
||||
osmApiConnections.push(defaultOsmApiConnections.dev);
|
||||
}
|
||||
|
||||
// auxiliary OSM services
|
||||
const taginfoApiUrl = 'https://taginfo.openstreetmap.org/api/4/';
|
||||
const nominatimApiUrl = 'https://nominatim.openstreetmap.org/';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user