Skip to content

Commit

Permalink
dev script
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Jun 11, 2024
1 parent 5c44370 commit 9fbf796
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
5 changes: 1 addition & 4 deletions linguaphoto/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ async def get_login_response(email: str, lifetime: int, crud: Crud) -> UserLogin

async def get_google_user_info(token: str) -> dict:
async with aiohttp.ClientSession() as session:
response = await session.get(
"https://www.googleapis.com/oauth2/v3/userinfo",
params={"access_token": token},
)
response = await session.get("https://www.googleapis.com/oauth2/v3/userinfo", params={"access_token": token})
if response.status != 200:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid Google token")
return await response.json()
Expand Down
3 changes: 3 additions & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .gitignore

*.log
15 changes: 15 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Composes DynamoDB Local, the DynamoDB Admin UI, and Redis
version: '3.7'

services:
dynamodb:
image: amazon/dynamodb-local
ports:
- "8000:8000"

dynamodb-admin:
image: aaronshaf/dynamodb-admin
ports:
- "8001:8001"
environment:
- DYNAMO_ENDPOINT=http://dynamodb:8000
53 changes: 53 additions & 0 deletions scripts/start_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh
# Starts the databases, frontend and backend.

set -e

cur_dir=$(realpath $(dirname $0))
root_dir=$(realpath $(dirname $cur_dir))

docker_log=${cur_dir}/docker.log
backend_log=${cur_dir}/backend.log
frontend_log=${cur_dir}/frontend.log

# Define cleanup function
cleanup() {
echo "Stopping databases..."
docker-compose -f ${cur_dir}/docker-compose.yml down
echo "Killing FastAPI..."
kill $backend_pid || true
echo "Killing React..."
kill $frontend_pid || true
echo "Waiting for services to stop..."
wait $docker_compose_pid
wait $backend_pid
wait $frontend_pid
echo "Services stopped."
}

# Set trap for cleanup on exit
trap cleanup EXIT

# Starts docker and gets the pid
docker-compose -f ${cur_dir}/docker-compose.yml up > $docker_log 2>&1 &
docker_compose_pid=$!

# Starts FastAPI and gets the pid
fastapi dev ${root_dir}/linguaphoto/main.py --port 8080 > $backend_log 2>&1 &
backend_pid=$!

# Starts React and gets the pid
cd ${root_dir}/frontend
npm start > $frontend_log 2>&1 &
frontend_pid=$!

# Wait for user to press enter
echo "====================================="
echo "Docker, FastAPI and React are running"
echo " Visit http://localhost:3000 "
echo "====================================="

read -p "Press enter to stop the services"

# Exits
exit 0

0 comments on commit 9fbf796

Please sign in to comment.