This repo holds the backend code for https://www.pkaindex.com.
To run locally:
- Download rust: https://rustup.rs/.
- (Optional) Install
sqlx-clifor running migrations and refreshing query metadata (You will needsqlite3even if you skip this step): https://github.com/launchbadge/sqlx/tree/main/sqlx-cli- Apply migrations (uses
DATABASE_URLfrom.env):sqlx migrate run - After altering SQL or migrations run
cargo sqlx prepare -- --bin pka_site_backendso the checked-in.sqlx/data stays in sync.
- Apply migrations (uses
- Download and install
redis. Make sureredis-serveris running on its default port6379. - Modify your hosts file and add the following entries if they aren't there already:
- 127.0.0.1 redis
- 0.0.0.0 pkaindextest.com www.pkaindextest.com
- Create a folder somewhere i.e
/Users/zak/Selfsigned/and generate self-signed SSL Certificate in this folder:- NOTE: When openssl asks you to enter
Common name:putpkaindextest.com openssl req -new -x509 -days 365 -nodes -out /Users/zak/Selfsigned/pkaindextest.pem -keyout /Users/zak/Selfsigned/pkaindextest.key -newkey rsa:2048
- NOTE: When openssl asks you to enter
- Modify
nginx.conffrom this project and replace the lines that haveYOUR_SELF_SIGNED_KEY_DIRECTORYwith the folder you created in the previous step. i.e/Users/zak/Selfsigned/ - Install
nginxand create the directoriessites-enabledandsites-availablein your/etc/nginxdirectory. - Copy the contents from
nginx.confinto a file calledpkaindextest.cominsidesites-availabled - Create a symbolic link between the file in
sites-availableandsites-enabledusing the command:ln -s /opt/homebrew/etc/nginx/sites-available/pkaindextest.com /opt/homebrew/etc/nginx/sites-enabled/pkaindextest.com - Modify
nginx.confin your system so that yourhttpblock includes this line:include sites-available/*;; - Start
nginx. - Generate YouTube API key from https://console.developers.google.com/ and save as env variable named: YT_API_KEY. Can pass empty string if you want however this means episodes won't be updated.
- Run the rust server
- To run in debug mode: run
cargo runfrom project root. - To run in release (optimized) mode: run
cargo run --releasefrom project root.
- To run in debug mode: run
- Rust should now be serving an API from http://0.0.0.0:1234.
- OpenAPI schema is available at http://0.0.0.0:1234/openapi.json.
- Visit https://pkaindextest.com in your browser. (Firefox will work but for Chrome you will need to import the Self Signed SSL certificate manually.)
docker build -t zakism/pka-index-backend:latest .docker run -p 1234:1234 zakism/pka-index-backend:latest- Rust should now be serving an API from http://0.0.0.0:1234.
docker-compose up -d