diff --git a/.env b/.env index 8c94fc4..5f82425 100644 --- a/.env +++ b/.env @@ -1,7 +1,7 @@ APIVERSION=1.2.3 ID=demoservice - PORT=80 +LIMIT=10 -LIMIT=10 \ No newline at end of file +CONFIG=local.config.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 35a5b90..50e125e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,20 +3,21 @@ FROM --platform=linux/amd64 node:alpine AS build_amd64 FROM --platform=linux/arm64 node:alpine AS build_arm64 -# Create app directory, our data will be in /usr/src/data -WORKDIR /usr/src/app +# Create app directory, our data will be in /usr/local/bin +WORKDIR /usr/local/bin/ocapi # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm@5+) COPY package*.json ./ - RUN npm install + # If you are building your code for production # RUN npm ci --only=production # Bundle app source -COPY . . +COPY src/ src/ +COPY local*.yml ./ EXPOSE 8080 diff --git a/config/demoservice.yml b/config/demoservice.yml deleted file mode 100644 index 8241983..0000000 --- a/config/demoservice.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -id: geonovumOAPI -title: Geonovum OGC API Demo Service -description: This OGC API Service is provided by Geonovum from instructional purposes only. The code onGitHub is written with readability in mind, not performance. -metadata: - contactName: Jane Doe - contactEmail: doe@acme.nl - creatorName: Then big creator - creatorUrl: https://data.somewhere.nl/ - publisherName: Acme Inc. - publisherUrl: https://www.example.com/ - licenseName: CC0 1.0 - licenseUrl: http://creativecommons.org/publicdomain/zero/1.0/deed.nl - attribution: 'data from somewhere' -api: -- buildingBlock: CRS - enabled: true - additionalCrs: - - code: 25832 - forceAxisOrder: NONE - - code: 4258 - forceAxisOrder: NONE - - code: 4326 - forceAxisOrder: NONE - - code: 3857 - forceAxisOrder: NONE diff --git a/local.config.yml b/local.config.yml new file mode 100644 index 0000000..fd46daf --- /dev/null +++ b/local.config.yml @@ -0,0 +1,32 @@ +--- +metadata: + identification: + title: Geonovum OGC API Demo Service + description: This OGC API Service is provided by Geonovum from instructional purposes only. The code onGitHub is written with readability in mind, not performance. + keywords: + - geospatial + - data + - api + contact: + contactName: Jane Doe + contactEmail: doe@acme.nl + creatorName: Then big creator + creatorUrl: https://data.somewhere.nl/ + publisherName: Acme Inc. + publisherUrl: https://www.example.com/ + license: + name: CC0 1.0 + url: http://creativecommons.org/publicdomain/zero/1.0/deed.nl +api: + version: 1.2.3 + buildingBlock: CRS + enabled: true + additionalCrs: + - code: 25832 + forceAxisOrder: NONE + - code: 4258 + forceAxisOrder: NONE + - code: 4326 + forceAxisOrder: NONE + - code: 3857 + forceAxisOrder: NONE diff --git a/src/app.js b/src/app.js index ba66dbd..ad5669b 100644 --- a/src/app.js +++ b/src/app.js @@ -20,8 +20,8 @@ export const app = express(); const __dirname = import.meta.dirname; if (__dirname === undefined) console.log("need node 20.16 or higher"); -const configPath = join(process.env.DATA_PATH || __dirname, "../config"); -const yamlStr = readFileSync(join(configPath, `${process.env.ID}.yml`)); +const configPath = join(__dirname, ".."); +const yamlStr = readFileSync(join(configPath, `local.config.yml`)); global.config = YAML.parse(yamlStr.toString()); app.use( diff --git a/src/database/database.js b/src/database/database.js index 54922e6..62d284f 100644 --- a/src/database/database.js +++ b/src/database/database.js @@ -1,17 +1,17 @@ import { join } from "path"; import YAML from "yaml"; -import { readdirSync, readFileSync } from "fs"; +import fs from "fs"; import { makeOAPIF } from "./geojsonParser.js"; function readGeoJSONfiles(dir) { - var fileNames = readdirSync(dir).filter((fn) => fn.endsWith(".geojson")); + var fileNames = fs.readdirSync(dir).filter((fn) => fn.endsWith(".geojson")); fileNames.forEach((fileName) => { - var rawData = readFileSync(join(dir, fileName)); + var rawData = fs.readFileSync(join(dir, fileName)); var geojson = JSON.parse(rawData); var ymlFilename = fileName.replace(/\.\w+$/, ".yml"); - var rawDataDef = readFileSync(join(dir, ymlFilename)); + var rawDataDef = fs.readFileSync(join(dir, ymlFilename)); var dataDef = YAML.parse(rawDataDef.toString()); var oapif = makeOAPIF(geojson, dataDef); @@ -24,7 +24,9 @@ function readGeoJSONfiles(dir) { var dataDict = {}; export function readData(dir) { - readGeoJSONfiles(dir); + if (fs.existsSync(dir)) readGeoJSONfiles(dir); + + console.log(`Found ${Object.keys(dataDict).length} datasets`); } export function getDatabases() { diff --git a/src/database/processes.js b/src/database/processes.js index b051e3b..03787f9 100644 --- a/src/database/processes.js +++ b/src/database/processes.js @@ -1,19 +1,23 @@ import { join } from "path"; -import { readdirSync, readFileSync } from "fs"; +import fs from "fs"; export async function readProcesses(dir) { - var fileNames = readdirSync(dir).filter((fn) => fn.endsWith(".json")); + if (fs.existsSync(dir)) { + var fileNames = fs.readdirSync(dir).filter((fn) => fn.endsWith(".json")); - fileNames.forEach((fileName) => { - var path = join(dir, fileName); - var rawData = readFileSync(path); - var json = JSON.parse(rawData); + fileNames.forEach((fileName) => { + var path = join(dir, fileName); + var rawData = fs.readFileSync(path); + var json = JSON.parse(rawData); - var oapip = json; - oapip.location = path; + var oapip = json; + oapip.location = path; - _processes[oapip.id] = oapip; - }); + _processes[oapip.id] = oapip; + }); + } + + console.log(`Found ${Object.keys(_processes).length} processes`); } var _processes = {}; diff --git a/src/index.js b/src/index.js index 756f330..5cabe60 100644 --- a/src/index.js +++ b/src/index.js @@ -8,9 +8,16 @@ if (__dirname === undefined) console.log("need node 20.16 or higher"); // Load data (TODO: async) try { - var dataPath = join(process.env.DATA_PATH || __dirname, "../data/datasets"); + var dataPath = join( + process.env.DATA_PATH || join(__dirname, "../data/"), + "datasets" + ); readData(dataPath); - var processenPath = join(process.env.DATA_PATH || __dirname, "../data/processes"); + + var processenPath = join( + process.env.DATA_PATH || join(__dirname, "../data"), + "processes" + ); readProcesses(processenPath); } catch (err) { console.log(err); diff --git a/src/models/common/collections/collections.js b/src/models/common/collections/collections.js index ef6588c..7c50c36 100644 --- a/src/models/common/collections/collections.js +++ b/src/models/common/collections/collections.js @@ -48,7 +48,6 @@ function getContent(neutralUrl, format, name, document) { // An optional title and description for the collection; content.title = document.name; content.description = document.description; - content.attribution = global.config.metadata.attribution; content.links = []; @@ -75,8 +74,8 @@ function get(neutralUrl, format, callback) { // (OAPIC P2) Requirement 3A: The content of that response SHALL be based upon the JSON schema collections.yaml. var content = {}; // An optional title and description for the collection; - content.title = global.config.title; - content.description = global.config.description; + content.title = global.config.metadata.identification.title; + content.description = global.config.metadata.identification.description; content.links = []; // (OAPIC P2) Requirement 2B. The API SHALL support the HTTP GET operation on all links to a Collections Resource that have the relation type content.links.push({ diff --git a/src/models/common/core/api.js b/src/models/common/core/api.js index a5f075c..ec989b2 100644 --- a/src/models/common/core/api.js +++ b/src/models/common/core/api.js @@ -31,10 +31,10 @@ function get(neutralUrl, callback) { var ff = JSON.stringify(content); - ff = ff.replace(new RegExp("{{:title}}", "g"), global.config.title); + ff = ff.replace(new RegExp("{{:title}}", "g"), global.config.metadata.identification.title); ff = ff.replace( new RegExp("{{:description}}", "g"), - global.config.description + global.config.metadata.identification.description ); ff = ff.replace(new RegExp("{{:version}}", "g"), process.env.APIVERSION); diff --git a/src/models/common/core/landingPage.js b/src/models/common/core/landingPage.js index 78e3664..0d54d7f 100644 --- a/src/models/common/core/landingPage.js +++ b/src/models/common/core/landingPage.js @@ -12,9 +12,8 @@ function get(neutralUrl, format, callback) { // - /conformance (relation type `conformance`) // - /collections (relation type `data`) var content = {}; - content.title = global.config.title; // Requirement 2 B - content.description = global.config.description; - content.attribution = global.config.metadata.attribution; + content.title = global.config.metadata.identification.title; // Requirement 2 B + content.description = global.config.metadata.identification.description; content.extent = {}; content.extent.spatial = {}; diff --git a/src/models/features/collection.js b/src/models/features/collection.js index ad3f698..138787a 100644 --- a/src/models/features/collection.js +++ b/src/models/features/collection.js @@ -66,8 +66,6 @@ function getMetaData(neutralUrl, format, name, document) { // An optional title and description for the collection; content.title = document.name; content.description = document.description; - content.attribution = - "this dataset is attributed to the municipality of amstelveen"; content.links = []; getLinks(neutralUrl, format, name, content.links);