Skip to content

Commit

Permalink
Add scripts to run locally
Browse files Browse the repository at this point in the history
  • Loading branch information
aliiyuu committed Aug 12, 2024
1 parent 40e6b9e commit 934ba77
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The scripts cover:
> [!WARNING]
> Always make sure you `git fetch` the latest changes.\
> NPM Install must be executed in `both frontend and server` directories to be able to deploy on fly.io successfully.
> In the server directory, make sure you create an `.env` file and set the variable `OPENAI_API_KEY` to your OpenAI API key.
## Scripts

Expand All @@ -23,10 +24,18 @@ This script installs NPM dependencies for both the `frontend` and `server` compo

This script deploys both the `frontend` and `server` components to `Fly.io.`

### 3. `run_all_tasks.sh`
### 3. `run_all_deploy.sh`

This script performs both the `NPM installation` and `Fly.io deployment` tasks sequentially. It installs dependencies for both frontend and server, then deploys them.

### 4. `start_local.sh`

This script starts both the `frontend` and `server` components on a local machine using two different ports.

### 4. `run_all_local.sh`

This script performs both the `NPM installation` and `start locally` tasks sequentially. It installs dependencies for both frontend and server, then starts both components locally.

### **Usage**:
1. Open your terminal.
2. Navigate to the `scripts` directory:
Expand Down
File renamed without changes.
54 changes: 54 additions & 0 deletions scripts/run_all_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

#define the server and client directories
SERVER="../server"
FRONTEND="../frontend"

#check if a port is available
check_port() {
PORT=$1
nc -z localhost $PORT
if [ $? -eq 0 ]; then
echo "Port $PORT is in use"
exit 1
fi
}

#install dependencies and start the server
start_server() {
echo "Navigating to server directory: $SERVER"
cd $SERVER || { echo "Server directory not found!"; exit 1;}

echo "Installing dependencies..."
npm install

#check if port 3000 is available
check_port 3000



echo "Starting server..."
node server.js
}

#install dependencies and start the frontend
start_frontend() {
echo "Navigating to client directory: $FRONTEND"
cd $FRONTEND || { echo "Frontend directory not found!"; exit 1; }

echo "Installing dependencies..."
npm install

echo "Starting frontend..."

TEST_PORT=3001
check_port TEST_PORT
while [ $? -eq 1 ]; do
TEST_PORT=$((TEST_PORT+1))
check_port TEST_PORT
done
PORT=TEST_PORT npm start
}

#run the server and frontend
start_server & start_frontend
26 changes: 26 additions & 0 deletions scripts/start_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

#define frontend and server directories
SERVER="../server"
FRONTEND="../frontend"

#start the server
start_server() {
echo "Navigating to server directory: $SERVER"
cd $SERVER || { echo "Server directory not found!"; exit 1;}

echo "Starting server..."
node server.js
}

#start the frontend
start_frontend() {
echo "Navigating to client directory: $FRONTEND"
cd $FRONTEND || { echo "Frontend directory not found!"; exit 1; }

echo "Starting frontend..."
PORT=3001 npm start
}

#run the server and frontend
start_server & start_frontend

0 comments on commit 934ba77

Please sign in to comment.