From 0c1c5dab87319bd6f40ebda133e5df42329435dc Mon Sep 17 00:00:00 2001 From: xdan Date: Thu, 31 Aug 2023 14:04:02 +0300 Subject: [PATCH] Move all ENV into config --- README.md | 2 +- src/app/config/types.ts | 17 +++++++++++++++++ src/tools/geojson-to-table-points-sql.ts | 7 ++++--- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/app/config/types.ts diff --git a/README.md b/README.md index 34cf512..968217a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ After that, you can load the data into the database on your test service. For example: ```sh -docker compose exec web node ./dist/tools/geojson-to-table-points-sql.js https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_admin_1_label_points.geojson +docker compose exec web POINTS_JSON=https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_admin_1_label_points.geojson node ./dist/tools/geojson-to-table-points-sql.js ``` The test server demonstrates how to load data by tiles and bbox (lower left and upper right points). diff --git a/src/app/config/types.ts b/src/app/config/types.ts new file mode 100644 index 0000000..ca1dd69 --- /dev/null +++ b/src/app/config/types.ts @@ -0,0 +1,17 @@ +export default interface Config { + port: number; + host: string; + defaultProvider: 'db' | 'json'; + db: { + user: string; + host: string; + database: string; + password: string; + port: number; + }, + pointsImportUrl: string; + cors: { + origin: string[] | boolean; + methods: Array<'POST' | 'GET' | 'PUT'> + } +} diff --git a/src/tools/geojson-to-table-points-sql.ts b/src/tools/geojson-to-table-points-sql.ts index d3095bb..ea8fd87 100644 --- a/src/tools/geojson-to-table-points-sql.ts +++ b/src/tools/geojson-to-table-points-sql.ts @@ -4,14 +4,15 @@ import got from 'got'; import type {FeatureCollection, Point} from 'geojson'; import {DB} from '../app/lib/pool'; import dotenv from 'dotenv'; +import {config} from "../app/config"; dotenv.config(); -// ts-node ./src/tools/geojson-to-table-points-sql.ts https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_admin_1_label_points.geojson +// POINTS_JSON=https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_admin_1_label_points.geojson ts-node ./src/tools/geojson-to-table-points-sql.ts -const file = process.argv[2]; -const fileUrl = new URL(file); +const fileUrl = new URL(config.pointsImportUrl); + if (!fileUrl.protocol || !fileUrl.host || !fileUrl.pathname) { console.error('Incorrect file url'); process.exit(0);