Compare commits

..
8 Commits
Author SHA1 Message Date
JosephFerano 4e05999df8 Fix README 2023-05-20 14:55:14 +07:00
JosephFerano a9c88d68e3 Don't render TOC 2023-05-20 14:41:10 +07:00
JosephFerano ed5ca366fe Added License and WIP Readme 2023-05-20 14:39:55 +07:00
JosephFerano 505c201654 Update TODOs 2023-05-19 19:44:44 +07:00
JosephFerano 88582d9ff3 Bad ChatGPT 2023-05-19 19:34:53 +07:00
JosephFerano f3a858956e Init db and and use dotenv to load database credentials 2023-05-19 19:19:17 +07:00
JosephFerano cd74846a7f Change URL 2023-05-19 17:16:43 +07:00
JosephFerano 52e38adcb7 Change port 2023-05-19 16:28:21 +07:00
6 changed files with 64 additions and 12 deletions

No files matched your search

+1 -1
View File
@@ -15,4 +15,4 @@ COPY . /app/
EXPOSE 8000 EXPOSE 8000
# Run api.py when the container launches # Run api.py when the container launches
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"] CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "3003"]
+20
View File
@@ -0,0 +1,20 @@
Copyright (c) 2023 Joseph Ferano - joseph@ferano.io
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+21
View File
@@ -0,0 +1,21 @@
#+TITLE: Zip My Link
#+AUTHOR: Joseph Ferano
#+OPTIONS: toc:nil
* About
This is a standard URL Shortening service built to practice web development.
Currently it works at providing the most basic feature which is to give the user
a shorter version of a URL they provide and then redirecting the user to the
site when consuming the link.
** What I'm using
- Python 3.11
- FastAPI
- CouchDB
- ~podman~ and ~podman-compose~
* COMMENT Local variables
;; Local Variables:
;; eval: (olivetti-mode t)
;; End:
+11 -2
View File
@@ -1,14 +1,23 @@
from fastapi import FastAPI, HTTPException from fastapi import FastAPI, HTTPException
from fastapi.responses import RedirectResponse, FileResponse from fastapi.responses import RedirectResponse, FileResponse
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from dotenv import load_dotenv
import couchdb import couchdb
import os
import uuid import uuid
import validators import validators
load_dotenv()
COUCHDB_USER = os.getenv("COUCHDB_USER")
COUCHDB_PASSWORD = os.getenv("COUCHDB_PASSWORD")
COUCHDB_HOST = os.getenv("COUCHDB_HOST")
COUCHDB_PORT = os.getenv("COUCHDB_PORT")
app = FastAPI() app = FastAPI()
app.mount("/static", StaticFiles(directory="static", html=True), name="static") app.mount("/static", StaticFiles(directory="static", html=True), name="static")
couch = couchdb.Server("http://admin:password@127.0.0.1:5984") couch = couchdb.Server(f"http://{COUCHDB_USER}:{COUCHDB_PASSWORD}@{COUCHDB_HOST}:{COUCHDB_PORT}")
@app.get("/") @app.get("/")
async def root(): async def root():
@@ -48,7 +57,7 @@ async def create_url(body: dict):
# TODO: Calculate how many unique IDs we are actually generating # TODO: Calculate how many unique IDs we are actually generating
url_id = uuid.uuid4().hex[:6] url_id = uuid.uuid4().hex[:6]
db[url_id] = { "full_url": body["url"], "user_id": body["username"] } db[url_id] = { "full_url": body["url"], "user_id": body["username"] }
return { "shortenedUrl": "http://localhost:8000/" + url_id } return { "shortenedUrl": "https://zipmy.link/" + url_id }
else: else:
raise HTTPException(status_code=400, detail="Url provided is invalid") raise HTTPException(status_code=400, detail="Url provided is invalid")
+10 -9
View File
@@ -4,15 +4,16 @@
* DONE Add button to copy shortened URL to clipboard * DONE Add button to copy shortened URL to clipboard
* DONE Add a 404 page in case the URL provided is invalid * DONE Add a 404 page in case the URL provided is invalid
* TODO RTFM on how to create docker compose files * DONE RTFM on how to create docker compose files
* TODO Containerize couchdb * DONE Containerize couchdb
* TODO Get the container running with the Dockerfile * DONE Get the container running with the Dockerfile
* TODO Point zipmy.link to joe-vps * DONE Point zipmy.link to joe-vps
- [ ] Add DNS records - [X] Add DNS records
- [ ] Add to nginx.conf - [X] Add to nginx.conf
- [ ] Generate certbot SSL cert - [X] Generate certbot SSL cert
* TODO Create a README.org * DONE Add MIT license
* TODO Add MIT license * INPROGRESS Create a README.org
* BACKLOG RTFM on how to create a container network * BACKLOG RTFM on how to create a container network
* BACKLOG Gitea Actions * BACKLOG Gitea Actions
+1
View File
@@ -3,3 +3,4 @@ uvicorn
couchdb couchdb
aiofiles aiofiles
validators validators
python-dotenv