Skip to content

Commit

Permalink
Move all ENV into config
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Aug 31, 2023
1 parent c0c3561 commit 0c1c5da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
17 changes: 17 additions & 0 deletions src/app/config/types.ts
Original file line number Diff line number Diff line change
@@ -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'>
}
}
7 changes: 4 additions & 3 deletions src/tools/geojson-to-table-points-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0c1c5da

Please sign in to comment.