Compare commits
8
Commits
1424fb2f43
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e05999df8 | ||
|
|
a9c88d68e3 | ||
|
|
ed5ca366fe | ||
|
|
505c201654 | ||
|
|
88582d9ff3 | ||
|
|
f3a858956e | ||
|
|
cd74846a7f | ||
|
|
52e38adcb7 |
No files matched your search
+1
-1
@@ -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"]
|
||||||
@@ -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
@@ -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:
|
||||||
@@ -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
@@ -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
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ uvicorn
|
|||||||
couchdb
|
couchdb
|
||||||
aiofiles
|
aiofiles
|
||||||
validators
|
validators
|
||||||
|
python-dotenv
|
||||||
Reference in new issue
Block a user