Skip to content

Commit 8ce00a1

Browse files
author
ibodev1
committed
Vercel Deployed 🎉
1 parent 2d152ce commit 8ce00a1

File tree

14 files changed

+4174
-0
lines changed

14 files changed

+4174
-0
lines changed

.gitignore

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
2+
# Created by https://www.toptal.com/developers/gitignore/api/node,vercel
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=node,vercel
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
.pnpm-debug.log*
14+
15+
# Diagnostic reports (https://nodejs.org/api/report.html)
16+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17+
18+
# Runtime data
19+
pids
20+
*.pid
21+
*.seed
22+
*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
lib-cov
26+
27+
# Coverage directory used by tools like istanbul
28+
coverage
29+
*.lcov
30+
31+
# nyc test coverage
32+
.nyc_output
33+
34+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35+
.grunt
36+
37+
# Bower dependency directory (https://bower.io/)
38+
bower_components
39+
40+
# node-waf configuration
41+
.lock-wscript
42+
43+
# Compiled binary addons (https://nodejs.org/api/addons.html)
44+
build/Release
45+
46+
# Dependency directories
47+
node_modules/
48+
jspm_packages/
49+
50+
# Snowpack dependency directory (https://snowpack.dev/)
51+
web_modules/
52+
53+
# TypeScript cache
54+
*.tsbuildinfo
55+
56+
# Optional npm cache directory
57+
.npm
58+
59+
# Optional eslint cache
60+
.eslintcache
61+
62+
# Optional stylelint cache
63+
.stylelintcache
64+
65+
# Microbundle cache
66+
.rpt2_cache/
67+
.rts2_cache_cjs/
68+
.rts2_cache_es/
69+
.rts2_cache_umd/
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variable files
81+
.env
82+
.env.development.local
83+
.env.test.local
84+
.env.production.local
85+
.env.local
86+
87+
# parcel-bundler cache (https://parceljs.org/)
88+
.cache
89+
.parcel-cache
90+
91+
# Next.js build output
92+
.next
93+
out
94+
95+
# Nuxt.js build / generate output
96+
.nuxt
97+
dist
98+
99+
# Gatsby files
100+
.cache/
101+
# Comment in the public line in if your project uses Gatsby and not Next.js
102+
# https://nextjs.org/blog/next-9-1#public-directory-support
103+
# public
104+
105+
# vuepress build output
106+
.vuepress/dist
107+
108+
# vuepress v2.x temp and cache directory
109+
.temp
110+
111+
# Docusaurus cache and generated files
112+
.docusaurus
113+
114+
# Serverless directories
115+
.serverless/
116+
117+
# FuseBox cache
118+
.fusebox/
119+
120+
# DynamoDB Local files
121+
.dynamodb/
122+
123+
# TernJS port file
124+
.tern-port
125+
126+
# Stores VSCode versions used for testing VSCode extensions
127+
.vscode-test
128+
129+
# yarn v2
130+
.yarn/cache
131+
.yarn/unplugged
132+
.yarn/build-state.yml
133+
.yarn/install-state.gz
134+
.pnp.*
135+
136+
### Node Patch ###
137+
# Serverless Webpack directories
138+
.webpack/
139+
140+
# Optional stylelint cache
141+
142+
# SvelteKit build / generate output
143+
.svelte-kit
144+
145+
### Vercel ###
146+
.vercel
147+
148+
# End of https://www.toptal.com/developers/gitignore/api/node,vercel
149+
150+
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
151+
152+
153+
.vercel

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 İbrahim Ödev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

api/404.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {type Request, type Response} from 'express';
2+
3+
export default (request: Request, response: Response) => {
4+
response.status(404).json({message: 'Not Found!'});
5+
};

api/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import app from "../app";
2+
import indexRouter from "../routes";
3+
4+
app.use("/api/", indexRouter);
5+
6+
export { default } from "../app";

app.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import process from "node:process";
2+
import express, {
3+
type Express,
4+
type NextFunction,
5+
type Request,
6+
type Response
7+
} from "express";
8+
import cors from "cors";
9+
import helmet from "helmet";
10+
11+
const PORT = process.env.PORT ?? 5000;
12+
13+
const app: Express = express();
14+
15+
app.set("port", PORT);
16+
app.use(helmet());
17+
app.use(cors());
18+
// app.use((request: Request, response: Response, next: NextFunction) => {
19+
// const isHTTPS =
20+
// request.headers["x-forwarded-proto"] &&
21+
// request.headers["x-forwarded-proto"] === "https";
22+
// if (isHTTPS || process.env.VERCEL_ENV === "development") {
23+
// next();
24+
// } else if (request.method === "GET") {
25+
// response.redirect(
26+
// 301,
27+
// "https://" + request.headers.host + request.originalUrl
28+
// );
29+
// } else {
30+
// response
31+
// .status(403)
32+
// .send("Please use HTTPS when submitting data to this server.");
33+
// }
34+
// });
35+
app.use(express.json());
36+
app.use((request: Request, response: Response, next: NextFunction) => {
37+
response.removeHeader("X-Powered-By");
38+
next();
39+
});
40+
app.use(express.urlencoded({ extended: false }));
41+
42+
export default app;

dev-server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import app from "./app";
2+
import logger from "morgan";
3+
import routes from "./routes/router";
4+
5+
app.use(logger("dev"));
6+
app.use("/", routes);
7+
8+
app.listen(app.get("port"), () => {
9+
console.log("Server started. Go to http://localhost:" + app.get("port"));
10+
});

package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "kandilli-api",
3+
"version": "0.0.2",
4+
"main": "dist/app.js",
5+
"license": "MIT",
6+
"type": "commonjs",
7+
"dependencies": {
8+
"cors": "^2.8.5",
9+
"express": "^4.18.2",
10+
"helmet": "^6.0.1",
11+
"jsdom": "^21.1.0"
12+
},
13+
"scripts": {
14+
"vercel:start": "vercel dev",
15+
"vercel:build": "vercel build",
16+
"vercel:deploy": "vercel deploy",
17+
"vercel:deploy:prod": "vercel deploy --prod",
18+
"build": "yarn clean && npx tsc --outDir dist",
19+
"dev": "concurrently \"npx tsc --watch\" \"nodemon -q dist/dev-server.js\"",
20+
"clean": "rimraf dist",
21+
"test": "xo",
22+
"test:fix": "xo --fix",
23+
"postversion": "git push -u origin main --tags"
24+
},
25+
"devDependencies": {
26+
"@types/cors": "^2.8.13",
27+
"@types/express": "^4.17.17",
28+
"@types/helmet": "^4.0.0",
29+
"@types/jsdom": "^21.1.0",
30+
"@types/morgan": "^1.9.4",
31+
"concurrently": "^7.6.0",
32+
"morgan": "^1.10.0",
33+
"nodemon": "^2.0.20",
34+
"rimraf": "^4.1.2",
35+
"typescript": "^4.9.5",
36+
"xo": "^0.53.1"
37+
}
38+
}

routes/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import express, { type Request, type Response } from "express";
2+
import { type Earthquake } from "../types/kandilli";
3+
import getEarthquakeList from "../utilities/kandilli";
4+
5+
const indexRouter = express.Router();
6+
7+
indexRouter.get("/", async (request: Request, response: Response) => {
8+
try {
9+
const earthquakeList: Earthquake[] | undefined = await getEarthquakeList();
10+
var responseData: Earthquake[] | undefined = earthquakeList;
11+
if (request.query.sehir) {
12+
responseData = responseData?.filter(
13+
(deprem: Earthquake) => deprem.sehir === request.query.sehir
14+
);
15+
}
16+
17+
if (
18+
request.query.limit &&
19+
Number(request.query.limit) >= 10 &&
20+
Number(request.query.limit) <= 500
21+
) {
22+
responseData = responseData?.slice(0, Number(request.query.limit));
23+
} else {
24+
responseData = responseData?.slice(0, 100);
25+
}
26+
27+
if (request.query.minml && Number(request.query.minml) > 0) {
28+
responseData = responseData?.filter(
29+
(deprem: Earthquake) =>
30+
parseFloat(deprem.ml) > Number(request.query.minml)
31+
);
32+
}
33+
34+
if (request.query.sort) {
35+
const sortedBy: any = request.query.sort.toString();
36+
// @ts-ignore
37+
responseData = responseData?.sort((a, b) => b[sortedBy] - a[sortedBy]);
38+
}
39+
40+
response.status(200).json(responseData);
41+
} catch (error: any) {
42+
response.status(400).end(error.toString());
43+
}
44+
});
45+
46+
export default indexRouter;

routes/router.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import express from "express";
2+
import indexRouter from "./index";
3+
4+
const routes = express.Router();
5+
6+
routes.use("/", indexRouter);
7+
8+
export default routes;

tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist",
4+
"target": "es2016",
5+
"module": "commonjs",
6+
"esModuleInterop": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"strict": true,
9+
"skipLibCheck": true
10+
}
11+
}

0 commit comments

Comments
 (0)