Skip to content

Latest commit

 

History

History
86 lines (64 loc) · 3.03 KB

File metadata and controls

86 lines (64 loc) · 3.03 KB

atcoder-problems-backend

atcoder-problems-backend is a set of backend applications written in Rust.

Since the web app, which is running on your local machine, connects to the production backend server, you don't need to run the backend applications in most cases.

Note that the following steps assume that your frontend application runs on http://localhost:3000 and your backend application runs on http://localhost:8080, which are the default values.

Prerequisites

  1. Create a GitHub app. Keep the client ID and the client secret.
    • Remember to set the "User authorization callback URL" to http://localhost:8080/internal-api/authorize.
  2. Launch an instance of PostgreSQL database on your machine.

Modifying Files

To prevent accidentally committing the changes below, you may want to ignore these files locally before editing them by adding the paths of these files to the $GIT_DIR/info/exclude file, if you do not intend to commit changes in these files. ($GIT_DIR is usually the .git folder.)

Below are the list of files you need to modify:

  • atcoder-problems-backend/src/server/endpoint/internal_api/mod.rs: change REDIRECT_URL to http://localhost:3000/atcoder/ for your backend to redirect to your frontend web app after logging in.
  • atcoder-problems-frontend/src/setupProxy.js: change target to http://localhost:8080 and remove the pathRewrite section for your frontend web app to use your backend server.
  • atcoder-problems-frontend/src/utils/Url.tsx: change CLIENT_ID to the client ID of your GitHub app and change AUTHORIZATION_CALLBACK_URL to http://localhost:8080/internal-api/authorize.

Be careful not to commit these files to the Git repository.

Build

docker-compose up -d
docker-compose exec backend-development cargo build

Run

export SQL_URL=... # Connection URL of PostgreSQL
export CLIENT_ID=... # GitHub client_id, which is required to use the login function.
export CLIENT_SECRET=... # GitHub client_secret, which is required to use the login function.

# Run backend server
cargo run --bin run_server

# Run crawlers
cargo run --bin crawl_all_submissions
cargo run --bin crawl_for_virtual_contests
cargo run --bin crawl_from_new_contests
cargo run --bin crawl_problems
cargo run --bin crawl_recent_submissions
cargo run --bin crawl_whole_contest <contest_id>

# Run other tools
cargo run --bin batch_update
cargo run --bin delta_update
cargo run --bin dump_json
cargo run --bin fix_invalid_submissions

Test

docker-compose up -d
docker-compose exec backend-development cargo test --workspace -- --test-threads=1

Format

GitHub Action will check if the code base is formatted by rustfmt. Please make sure that your change is formatted before sending a pull request. You can format the code base with cargo fmt like the following:

docker-compose up -d
docker-compose exec backend-development cargo fmt