Flask and create-react-app
npm install
pip install -r requirements.txt
- Run
echo "DANGEROUSLY_DISABLE_HOST_CHECK=true" > .env.development.local
in the project directory
- Run command in terminal (in your project directory):
python app.py
- Run command in another terminal,
cd
into the project directory, and runnpm run start
- Preview web page in browser '/'
Don't do the Heroku step for assignments, you only need to deploy for Project 2
- Create a Heroku app:
heroku create --buildpack heroku/python
- Add nodejs buildpack:
heroku buildpacks:add --index 1 heroku/nodejs
- Push to Heroku:
git push heroku main
- Install PostGreSQL:
sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
Enter yes to all prompts. - Initialize PSQL database:
sudo service postgresql initdb
- Start PSQL:
sudo service postgresql start
- Make a new superuser:
sudo -u postgres createuser --superuser $USER
If you get an error saying "could not change directory", that's okay! It worked! - Make a new database:
sudo -u postgres createdb $USER
If you get an error saying "could not change directory", that's okay! It worked! - Make sure your user shows up:
- a)
psql
- b)
\du
look for ec2-user as a user (take a screenshot) - c)
\l
look for ec2-user as a database (take a screenshot)
- a)
- Make a new user:
- a)
psql
(if you already quit out of psql) - b) Type this with your username and password (DONT JUST COPY PASTE):
create user some_username_here superuser password 'some_unique_new_password_here';
e.g.create user namanaman superuser password 'mysecretpassword123';
- c) \q to quit out of sql
- a)
- Save your username and password in a
sql.env
file with the formatSQL_USER=
andSQL_PASSWORD=
. - To use SQL in Python:
pip install psycopg2-binary
pip install Flask-SQLAlchemy==2.1
- Created socketio for passing the username and the score list.
- Created an if statement where idon't pass the person if it's already in the database.
- When the person is not in the database, it adds that person.
- I used sqlalchemy to get result score in decending order.
- To add and remove points I added new on_result(data).
- on_result(data) I'm sending the data to Board.js, which checks if the user is in the database and prints the data in frontend.
- Then I'm using map function to print out the database and score.
- When the board resets and user wins, That user is getting extra points.
- Spectators are allowed to reset the Board.
- User is able to click X and O on the same board.
- When the second user does the first move and wins, It shows the first player as a winner. But the score changes for the right user.
- I had problem where names weren't printing. -> To fix that I used map statement from one of the lectures.
- Score list was printing as a string, I added the ['score'] as this and it worked for the list.
- For the decending order -> Used sqlalchemy before the score gets send to the script.