Skip to content

Commit

Permalink
feat: fix setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv-1001 committed Dec 5, 2024
1 parent 60597c2 commit 1a411f7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgresql://admin:password@192.168.1.43:5555/gis
41 changes: 37 additions & 4 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
mkdir ./src/geojson-data

is_wget2_installed() {
if command -v wget2 &> /dev/null; then
return 0 # wget2 is installed
else
return 1 # wget2 is not installed
fi
}

if is_wget2_installed; then
echo "wget2 is already installed."
else
# Check if the OS is macOS or Linux
if [[ "$(uname)" == "Darwin" ]]; then
echo "macOS detected. Installing wget2 using Homebrew..."
# Check if Homebrew is installed, if not install it
if ! command -v brew &> /dev/null; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Install wget2 using Homebrew
brew install wget
elif [[ "$(uname)" == "Linux" ]]; then
echo "Linux detected. Installing wget2 using apt..."
# Update package list and install wget2 using apt
sudo apt update
sudo apt install wget2 -y
else
echo "Unsupported OS detected."
exit 1
fi
fi

# curl -o ./db.mmdb -L --fail --compressed https://mmdbcdn.posthog.net
# getting the latest db.mmdb
curl -o ./db.mmdb -L --fail --compressed https://mmdbcdn.posthog.net
wget2 -O db.mmdb https://mmdbcdn.posthog.net

cd ./src

Expand Down Expand Up @@ -45,6 +78,6 @@ cd ../..
# Updating geoJSON files through script to make them usable in src
cd ./scripts
npx ts-node parse.geojson.ts

# Changing PWD back to /server/
cd - &> /dev/null
npx ts-node ingestors/state.geojson.ts
npx ts-node ingestors/district.geojson.ts
npx ts-node ingestors/subdistrict.geojson.ts
6 changes: 2 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ async function bootstrap() {
const logger = new Logger('Main'); // 'Main' is the context name

const configService = app.get(ConfigService);
const port = configService.get<number>('port');
const host = configService.get<string>('host');

// Register plugins and middleware
await app.register(multipart);
Expand All @@ -44,8 +42,8 @@ async function bootstrap() {
SwaggerModule.setup('api-docs', app, document);

// Start the server
await app.listen(port, host, (err, address) => {
logger.log(`Server running on ${host}:${port}`);
await app.listen(3000, '0.0.0.0', (err, address) => {
logger.log(`Server running on 0.0.0.0:3000`);
});

// Log additional information as needed
Expand Down
4 changes: 2 additions & 2 deletions src/modules/georev/georev.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('GeorevController', () => {
const result = await controller.getGeoRev(lat, lon);
} catch (error) {
expect(error).toBeInstanceOf(HttpException);
expect(error.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
expect(error.getStatus()).toBe(HttpStatus.BAD_REQUEST);
expect(error.getResponse()).toEqual({
status: 'fail',
error: 'lat lon query missing',
Expand All @@ -98,7 +98,7 @@ describe('GeorevController', () => {
}
catch (error) {
expect(error).toBeInstanceOf(HttpException);
expect(error.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
expect(error.getStatus()).toBe(HttpStatus.BAD_REQUEST);
expect(error.getResponse()).toEqual({
status: 'fail',
error: 'Invalid latitude or longitude',
Expand Down
4 changes: 2 additions & 2 deletions src/modules/georev/georev.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export class GeorevController {
this.logger.error(`lat lon query missing`);
throw new HttpException(
{ status: 'fail', error: `lat lon query missing` },
HttpStatus.INTERNAL_SERVER_ERROR,
HttpStatus.BAD_REQUEST,
);
}

if (!this.geoRevService.isValidLatitudeLongitude(lat, lon)) {
this.logger.error('Invalid latitude or longitude');
throw new HttpException(
{ 'status': 'fail', 'error': 'Invalid latitude or longitude' },
HttpStatus.INTERNAL_SERVER_ERROR,
HttpStatus.BAD_REQUEST,
);
}

Expand Down

0 comments on commit 1a411f7

Please sign in to comment.