diff --git a/README.md b/README.md index 4823f2b..cfdf682 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,77 @@ # hbd -Birthday bot backend and frontend +HBD is a simple application (which you can self-host) that serves birthday reminders through telegram. -## Migrations +## Usage -### Postgres +The application usage is very straightforward: -#### Up +1. Sign up for an account + + Requires an email, password, reminder time, timezone, [telegram bot API key](#bot-api-key), and [telegram chat ID](#chat-id) +2. Add birthdays +3. Receive reminders -```bash -migrate -database 'postgres://postgres:postgres@localhost:6684/postgres?sslmode=disable' -path ./migrations up -``` +### Getting a bot API key and chat ID -#### Down +#### Bot API key -```bash -migrate -database 'postgres://postgres:postgres@localhost:6684/postgres?sslmode=disable' -path ./migrations down -``` +1. Open Telegram +2. Search for `BotFather` +3. Start a chat with `BotFather` +4. Use the `/newbot` command to create a new bot +5. Follow the instructions to create a new bot +6. Copy the API key -#### Down to last migration +Through this API key the application can send messages to you through the bot. -```bash -migrate -database 'postgres://postgres:postgres@localhost:6684/postgres?sslmode=disable' -path ./migrations down 1 +#### Chat ID + +1. Open Telegram on your mobile device +2. Send `/start` to your newly created bot +3. Send a message to the bot +4. Open the following URL in your browser: `https://api.telegram.org/bot/getUpdates` +5. Look for the `chat` object in the JSON response +6. Copy the `id` field + +Using this ID the application can send messages to your chat specifically. + +## Self-hosting + +### Docker + +The application is containerized using docker, we use sqlite as the database by default. + +#### Docker compose + +The repo includes two docker-compose files. + +1. `docker-compose.yml` - This file is used to run the application locally with no reverse proxy. This works fine for use within a local network. We map the ports `8417` and `8418` to the host machine. Port `8417` is the backend port and port `8418` is the frontend port. + +```yaml +--- +services: + hbd: + build: + context: . + dockerfile: Dockerfile + container_name: hbd + ports: + - "8417:8417" + - "8418:8418" + volumes: + - ./hbd-data:/app + environment: + - DB_TYPE=sqlite + - DATABASE_URL=/app/backend/hbd.db + - MASTER_KEY=35e150e7ca83247f18cb1a37d61d8e161dddec06027f5db009b34da48c25f1b5 + - PORT=8418 + - ENVIRONMENT=development + - CUSTOM_DOMAIN_FRONTEND=https://hbd.lotiguere.com + - CUSTOM_DOMAIN_BACKEND=https://hbd-api.lotiguere.com ``` +## Migrations + ### SQLite #### Up diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index 2b9b9e3..bccc2c8 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -5,6 +5,8 @@ services: context: . dockerfile: Dockerfile container_name: hbd + volumes: + - ./hbd-data:/app restart: always environment: - DB_TYPE=sqlite diff --git a/docker-compose.yml b/docker-compose.yml index 26baca5..ae7938a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,3 @@ services: - ENVIRONMENT=development - CUSTOM_DOMAIN_FRONTEND=https://hbd.lotiguere.com - CUSTOM_DOMAIN_BACKEND=https://hbd-api.lotiguere.com - -networks: - default: - name: hbd-network diff --git a/frontend/app/favicon.ico b/frontend/app/favicon.ico index 718d6fe..07e74b9 100644 Binary files a/frontend/app/favicon.ico and b/frontend/app/favicon.ico differ diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 53e3d3d..19014ae 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -21,10 +21,10 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { OctagonAlert, CircleHelp, - GitPullRequestArrow, BookOpen, Coffee, } from "lucide-react"; +import { GitHubLogoIcon } from "@radix-ui/react-icons"; import { Select, SelectTrigger, @@ -509,7 +509,7 @@ export default function Home() { target="_blank" rel="noopener noreferrer" > - + diff --git a/frontend/lib/api/apiService.js b/frontend/lib/api/apiService.js index 46e228d..c0ea655 100644 --- a/frontend/lib/api/apiService.js +++ b/frontend/lib/api/apiService.js @@ -1,10 +1,7 @@ - import axios from 'axios'; -var baseURL = 'https://hbd-api.lotiguere.com'; -if (process.env.ENVIRONMENT === 'production') { - baseURL = 'https://hbd-api.lotiguere.com'; -} +var baseURL = process.env.ENVIRONMENT === 'production' ? 'https://hbd-api.lotiguere.com' : 'http://localhost:8417'; + // Create an Axios instance const api = axios.create({ diff --git a/frontend/lib/api/axiosConfig.js b/frontend/lib/api/axiosConfig.js deleted file mode 100644 index f18c2e6..0000000 --- a/frontend/lib/api/axiosConfig.js +++ /dev/null @@ -1,38 +0,0 @@ -import axios from 'axios'; - -var baseURL = 'https://hbd-api.lotiguere.com'; -if (process.env.ENVIRONMENT === 'production') { - baseURL = 'https://hbd-api.lotiguere.com'; -} - -// Create an Axios instance -const api = axios.create({ - baseURL: baseURL, - headers: { - 'Content-Type': 'application/json', - }, -}); - -// Interceptor to handle requests -api.interceptors.request.use( - (config) => { - // Add authorization token or other headers if necessary - // config.headers.Authorization = `Bearer ${token}`; - return config; - }, - (error) => { - // Handle the error - return Promise.reject(error); - } -); - -// Interceptor to handle responses -api.interceptors.response.use( - (response) => response, - (error) => { - // Handle errors, e.g., display notifications or log errors - return Promise.reject(error); - } -); - -export default api;