Skip to content

Commit 217e347

Browse files
committed
fetching DATABASE_NAME from env
1 parent d212c41 commit 217e347

File tree

6 files changed

+288
-1285
lines changed

6 files changed

+288
-1285
lines changed

README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# 🔗 tiny URL Generator
22

3-
> A modern, Bitly-style tiny URL web application built with Flask, FastAPI & MongoDB
3+
> A modern, Bitly-style tiny URL web application built with FastAPI & MongoDB
44
55
![Python](https://img.shields.io/badge/Python-3.10-blue.svg)
6-
![Flask](https://img.shields.io/badge/Flask-Web%20Framework-black.svg)
76
![MongoDB](https://img.shields.io/badge/Database-MongoDB-green.svg)
87
![License](https://img.shields.io/badge/License-MIT-yellow.svg)
98
![Status](https://img.shields.io/badge/Status-Active-success.svg)
@@ -12,12 +11,11 @@
1211

1312
## 📌 Overview
1413

15-
**tiny URL** is a sleek, fast, and modern URL shortening platform built using **Flask**, **FastAPI**, and **MongoDB**.
14+
**tiny URL** is a sleek, fast, and modern URL shortening platform built using **FastAPI**, and **MongoDB**.
1615
It converts long URLs into short, shareable links — just like Bitly.
1716

1817
The project supports both:
1918

20-
- 🌐 **Flask Web UI** (end users)
2119
- 🚀 **FastAPI REST API** (developers / integrations)
2220

2321
---
@@ -37,7 +35,6 @@ The project supports both:
3735
- Mobile-friendly QR Codes
3836
- Fully responsive design
3937
- Recent URLs page
40-
- Glassmorphism UI
4138

4239
---
4340

@@ -75,17 +72,15 @@ def generate_code(length=6):
7572

7673
🗃️ Tech Stack
7774

78-
| Layer | Technology |
79-
| ----------- | -------------------------- |
80-
| UI Backend | Flask |
81-
| API Backend | FastAPI |
82-
| Database | MongoDB |
83-
| Frontend | HTML, CSS, Vanilla JS |
84-
| UI Style | Glassmorphism, Gradient UI |
85-
| API Server | Uvicorn |
86-
| Validation | Pydantic v2 |
87-
| CLI | Click |
88-
| Data | JSON |
75+
| Layer | Technology |
76+
| ----------- | --------------------- |
77+
| API Backend | FastAPI |
78+
| Database | MongoDB |
79+
| Frontend | HTML, CSS, Vanilla JS |
80+
| API Server | Uvicorn |
81+
| Validation | Pydantic v2 |
82+
| CLI | Click |
83+
| Data | JSON |
8984

9085
📁 Project Folder Structure
9186

app/db/data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def connect_db():
1818
global client, db, urls, url_stats
1919

2020
MONGO_URI = os.getenv("MONGO_URI")
21-
22-
print("🔎 MONGO_URI =", MONGO_URI)
21+
# Default to "tiny_url" if the ENV variable is missing
22+
DB_NAME = os.getenv("DATABASE_NAME", "tiny_url")
2323

2424
if not MONGO_URI:
2525
print("⚠️ MONGO_URI is not set. Running in NO-DB mode.")
@@ -29,11 +29,11 @@ def connect_db():
2929
client = MongoClient(MONGO_URI, serverSelectionTimeoutMS=2000)
3030
client.admin.command("ping")
3131

32-
db = client["tiny_url"]
32+
db = client[DB_NAME]
3333
urls = db["urls"]
3434
url_stats = db["url_stats"]
3535

36-
print("✅ MongoDB connected successfully")
36+
print(f"✅ MongoDB connected successfully to database: '{DB_NAME}'")
3737
return True
3838

3939
except ServerSelectionTimeoutError:

app/static/qr/zSDrr0.png

40.1 KB
Loading

app/static/style.css

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ button {
3939
font-weight: 600;
4040
}
4141

42-
4342
.dark-theme h1 {
4443
background: linear-gradient(90deg, #ffffff, #dddddd, #ffffff);
4544
-webkit-background-clip: text;
@@ -100,10 +99,8 @@ button {
10099

101100
.input-field input {
102101
color: #000 !important;
103-
104102
}
105103

106-
107104
.dark-theme .input-field input {
108105
color: #fff !important;
109106
}
@@ -119,7 +116,6 @@ button {
119116
transition: background-color 9999s ease-in-out 0s;
120117
}
121118

122-
123119
.input-field input:-webkit-autofill {
124120
-webkit-text-fill-color: #000 !important;
125121
}
@@ -156,7 +152,6 @@ button {
156152
background: linear-gradient(180deg, #0b1220, #050b14);
157153
}
158154

159-
160155
footer {
161156
margin-top: 0;
162157
}
@@ -267,7 +262,6 @@ body.dark-theme {
267262
--muted: #9aa7a6;
268263
}
269264

270-
271265
.page {
272266
flex: 1;
273267
display: flex;
@@ -276,10 +270,8 @@ body.dark-theme {
276270
gap: 1rem;
277271
padding: 2rem;
278272
min-height: 80vh;
279-
280273
}
281274

282-
283275
.theme-toggle {
284276
background: transparent;
285277
border: none;
@@ -374,7 +366,7 @@ body.dark-theme {
374366
}
375367

376368
.short-actions {
377-
display:flex;
369+
display: flex;
378370
justify-content: center;
379371
align-items: center;
380372
gap: 8px;
@@ -383,7 +375,6 @@ body.dark-theme {
383375
background: linear-gradient(180deg, rgba(75, 194, 176, 0.06), rgba(94, 207, 255, 0.04));
384376
}
385377

386-
387378
.short-box input {
388379
align-items: center;
389380
padding: 10px;
@@ -436,12 +427,12 @@ body.dark-theme {
436427
}
437428

438429
.qr-block img {
439-
width: 160px;
440-
height: 160px;
430+
height: 15rem;
441431
align-items: center;
442-
border-radius: 12px;
432+
aspect-ratio: 1;
443433
box-shadow: 0 10px 20px rgba(10, 20, 30, 0.06);
444-
background: #fff;
434+
outline: 2px solid green;
435+
outline-offset: 4px;
445436
}
446437

447438
.download-qr {
@@ -502,16 +493,15 @@ body.dark-theme {
502493
}
503494

504495
footer {
505-
min-height: auto;
496+
min-height: auto;
506497
}
507498

508499
.app-footer {
509500
background: white;
510501
color: #e5e7eb;
511502
padding: 8px 10px;
512-
margin-top: auto;
503+
margin-top: auto;
513504
position: relative;
514-
515505
}
516506
.dark-theme .app-footer {
517507
background: linear-gradient(180deg, #0b1220, #050b14);
@@ -525,8 +515,6 @@ footer {
525515
flex-wrap: wrap;
526516
}
527517

528-
529-
530518
.footer-brand {
531519
max-width: 420px;
532520
}
@@ -590,7 +578,6 @@ footer {
590578
transform: translateY(-2px);
591579
}
592580

593-
594581
.footer-links {
595582
display: flex;
596583
gap: 80px;
@@ -614,7 +601,7 @@ footer {
614601
}
615602

616603
.footer-col a:hover {
617-
text-decoration: underline;
604+
text-decoration: underline;
618605
}
619606

620607
/* Bottom */
@@ -658,7 +645,6 @@ footer {
658645
overflow-x: auto;
659646
}
660647

661-
662648
.recent-table {
663649
width: 100%;
664650
border-collapse: collapse;
@@ -669,7 +655,7 @@ footer {
669655
.recent-table thead {
670656
background: rgb(0, 0, 0);
671657
}
672-
.recent-table th{
658+
.recent-table th {
673659
color: rgb(0, 0, 0);
674660
padding: 8px 14px;
675661
text-align: left;
@@ -726,7 +712,6 @@ td {
726712
font-weight: 700;
727713
}
728714

729-
730715
.original-url {
731716
color: #22c55e;
732717
word-break: break-all;
@@ -823,9 +808,8 @@ td {
823808
}
824809
.info-box {
825810
margin-bottom: 15px;
826-
padding: 10px;
827-
color: #0e34f6;
828-
border-radius: 8px;
829-
font-weight: 700;
830-
831-
}
811+
padding: 10px;
812+
color: #0e34f6;
813+
border-radius: 8px;
814+
font-weight: 700;
815+
}

0 commit comments

Comments
 (0)