This repo holds the backend code for https://www.pkaindex.com.
To run locally:
- Download rust: https://rustup.rs/.
- (Optional) Install
sqlx-cli
for running migrations and refreshing query metadata (You will needsqlite3
even if you skip this step): https://github.com/launchbadge/sqlx/tree/main/sqlx-cli- Apply migrations (uses
DATABASE_URL
from.env
):sqlx migrate run
- After altering SQL or migrations run
cargo sqlx prepare -- --bin pka_site_backend
so the checked-in.sqlx/
data stays in sync.
- Apply migrations (uses
- Download and install
redis
. Make sureredis-server
is 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.conf
from this project and replace the lines that haveYOUR_SELF_SIGNED_KEY_DIRECTORY
with the folder you created in the previous step. i.e/Users/zak/Selfsigned/
- Install
nginx
and create the directoriessites-enabled
andsites-available
in your/etc/nginx
directory. - Copy the contents from
nginx.conf
into a file calledpkaindextest.com
insidesites-availabled
- Create a symbolic link between the file in
sites-available
andsites-enabled
using the command:ln -s /opt/homebrew/etc/nginx/sites-available/pkaindextest.com /opt/homebrew/etc/nginx/sites-enabled/pkaindextest.com
- Modify
nginx.conf
in your system so that yourhttp
block 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 run
from project root. - To run in release (optimized) mode: run
cargo run --release
from 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