Skip to content

Commit

Permalink
reorg config.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Sep 14, 2024
1 parent a0c5843 commit a3a0173
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
APIVERSION=1.2.3

ID=demoservice

PORT=80
LIMIT=10

LIMIT=10
CONFIG=local.config.yml
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 0 additions & 26 deletions config/demoservice.yml

This file was deleted.

32 changes: 32 additions & 0 deletions local.config.yml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 7 additions & 5 deletions src/database/database.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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() {
Expand Down
24 changes: 14 additions & 10 deletions src/database/processes.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/models/common/collections/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions src/models/common/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/models/common/core/landingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
2 changes: 0 additions & 2 deletions src/models/features/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a3a0173

Please sign in to comment.