Skip to content

Commit

Permalink
feat: switch to deno and hono 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodev1 committed Nov 5, 2024
1 parent 1d0a7ce commit bf3a95c
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 5,285 deletions.
34 changes: 12 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
### Deno ###
/.idea/
/.vscode/

/node_modules

.env
*.orig
*.pyc
*.swp

### Node ###
# Logs
logs
Expand Down Expand Up @@ -74,7 +85,6 @@ web_modules/
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
Expand Down Expand Up @@ -138,9 +148,6 @@ dist
# SvelteKit build / generate output
.svelte-kit

### Vercel ###
.vercel

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
Expand Down Expand Up @@ -184,21 +191,4 @@ $RECYCLE.BIN/
*.msp

# Windows shortcuts
*.lnk

### yarn ###
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored

.yarn/*
!.yarn/releases
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions

# if you are NOT using Zero-installs, then:
# comment the following lines
!.yarn/cache

# and uncomment the following lines
# .pnp.*
*.lnk
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 İbrahim Ödev
Copyright (c) 2024 İbrahim Ödev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 4 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
# Kandilli API

[Kandilli Rasathanesi ve Deprem Araştırma Enstitüsü](http://www.koeri.boun.edu.tr/scripts/lst1.asp)'nün son depremler listesinin REST API halidir. Vercel REST API desteği üctretsiz olduğu sürece ücretsizdir. Hiçbir ticari amaç için kullanılmamaktadır. İletişim için [mail adresim](mailto:[email protected]).
[Kandilli Rasathanesi ve Deprem Araştırma Enstitüsü](http://www.koeri.boun.edu.tr/scripts/lst1.asp)'nün son depremler listesinin REST API biçimidir. Ticari
amaçlarla kullanılmaması gerekmektedir. İletişim için [mail adresim](mailto:[email protected]) üzerinden ulaşabilirsiniz.

## Son 100 deprem
## Son 500 deprem

[https://kandilli-api.vercel.app/api](https://kandilli-api.vercel.app/api)

## Örnek Sorgu URL

[https://kandilli-api.vercel.app/api?sort=ml&minml=4&sehir=ELAZIG&limit=500](https://kandilli-api.vercel.app/api?sort=ml&minml=4&sehir=ELAZIG&limit=500)

500 deprem arasından ELAZIG şehrindeki minimum 4 büyüklüğündeki depremleri deprem büyüklüğüne göre sıralaması için bir sorgu.

## Filtrelemeler

Daha iyi veriler elde etmeniz için birkaç filtreleme ekledim.

### ?sehir=

Büyük harflerle ve ingilizce karakterlere uygun bir şekilde türkiyedeki şehirlerden herhangi birisine göre verileri sıralatabilirsiniz.

### ?limit=

`10` büyük ve `500` küçük olacak şekilde istediğiniz sayıda veri getirebilirsiniz. Varsayılan ```100```.

### ?sort=

En büyükten en küçüğe olacak şekilde sıralmasını istediğiniz anahtar değeri yazarasnız ona göre sıralar.

### ?minml=

Depremin büyüklük değeri olan ml nin minumum değerine göre verileri getirebilirsiniz.
[https://kandilli.deno.dev/](https://kandilli.deno.dev/)
5 changes: 0 additions & 5 deletions api/404.ts

This file was deleted.

6 changes: 0 additions & 6 deletions api/index.ts

This file was deleted.

25 changes: 0 additions & 25 deletions app.ts

This file was deleted.

32 changes: 32 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"lock": false,
"tasks": {
"dev": "deno run --allow-all --watch main.ts",
"check": "deno check **/*.ts",
"deploy": "deployctl deploy",
"deploy:prod": "deployctl deploy --prod"
},
"fmt": {
"semiColons": true,
"singleQuote": true,
"lineWidth": 160
},
"compilerOptions": {
"strict": true
},
"lint": {
"rules": {
"exclude": ["no-explicit-any"]
}
},
"imports": {
"deno-dom": "jsr:@b-fuze/deno-dom",
"hono": "jsr:@hono/hono"
},
"deploy": {
"project": "e10af582-079f-402c-be3c-407adf702279",
"exclude": ["**/node_modules"],
"include": [],
"entrypoint": "main.ts"
}
}
10 changes: 0 additions & 10 deletions dev-server.ts

This file was deleted.

33 changes: 33 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { logger } from 'hono/logger';
import { prettyJSON } from 'hono/pretty-json';
import { secureHeaders } from 'hono/secure-headers';
import indexRouter from './routes/index.ts';

const app = new Hono();

// Middlewares
app.use('*', logger(), cors(), prettyJSON(), secureHeaders());

// Routes
app.route('/', indexRouter);

app.notFound((c) => {
return c.json({
message: '404 Not Found',
});
});

app.onError((error, c) => {
return c.json(error);
});

const PORT = Number.parseInt(Deno.env.get('PORT') || '8000');

Deno.serve({
port: PORT,
onListen: ({ port }) => {
console.info(`Listening on http://localhost:${port}`);
},
}, app.fetch);
37 changes: 0 additions & 37 deletions package.json

This file was deleted.

47 changes: 6 additions & 41 deletions routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
import express, {type Request, type Response} from 'express';
import {type Earthquake} from '../types/kandilli.js';
import getEarthquakeList from '../utilities/kandilli.js';
import { Hono } from 'hono';
import fetchEarthquakeData from '../utilities/kandilli.ts';

const indexRouter = express.Router();
const indexRouter = new Hono();

indexRouter.get('/', async (request: Request, response: Response) => {
try {
const earthquakeList: Earthquake[] | undefined = await getEarthquakeList();
let responseData: Earthquake[] | undefined = earthquakeList;
if (request.query.sehir) {
responseData = responseData?.filter(
(deprem: Earthquake) => deprem.sehir === request.query.sehir,
);
}

if (
request.query.limit
&& Number(request.query.limit) >= 10
&& Number(request.query.limit) <= 500
) {
responseData = responseData?.slice(0, Number(request.query.limit));
} else {
responseData = responseData?.slice(0, 100);
}

if (request.query.minml && Number(request.query.minml) > 0) {
responseData = responseData?.filter(
(deprem: Earthquake) =>
Number.parseFloat(deprem.ml) > Number(request.query.minml),
);
}

if (request.query.sort) {
const sortedBy: any = request.query.sort.toString();
// @ts-expect-error
responseData = responseData?.sort((a, b) => b[sortedBy] - a[sortedBy]);
}

response.status(200).json(responseData);
} catch (error: any) {
response.status(400).end(error.toString());
}
indexRouter.get('/', async (c) => {
const earthquakeList = await fetchEarthquakeData();
return c.json(earthquakeList, 200);
});

export default indexRouter;
8 changes: 0 additions & 8 deletions routes/router.ts

This file was deleted.

15 changes: 0 additions & 15 deletions tsconfig.json

This file was deleted.

25 changes: 12 additions & 13 deletions types/kandilli.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export type Earthquake = {
id: string;
tarih: string;
saat: string;
enlem: string;
boylam: string;
derinlik: string;
md: string;
ml: string;
mw: string;
yer: string;
sehir: string;
bolge: string;
nitelik: string;
date: string;
time: string;
latitude: string;
longitude: string;
depth: string;
md: string;
ml: string;
mw: string;
location: string;
city?: string;
region: string;
quality: string;
};
7 changes: 0 additions & 7 deletions utilities/gen-id.ts

This file was deleted.

Loading

0 comments on commit bf3a95c

Please sign in to comment.