Setup

Getting Started

To start developing on the backend, you must clone the repository from GitHub.

Installing Rust

You can skip this step if you already have Rust installed on your system, preferably by using Rustup.

  1. If you have installed Rust by any other means (i.e. system package manager) that is not Rustup, we recommend that you reinstall using Rustup to let it manage the Rust toolchain for you.

  2. Go to rustup.rs and follow the instructions on the website to have Rust installed on your system.

  3. Double-check that both the rustc and cargo executables are available on your preferred shell's PATH environment.

Cloning the Repository

  1. Ensure you have Git installed on your system, if not, you can download Git from here.

  2. Open your preferred terminal application and navigate to the directory you want to store the MySK API repository on your system.

  3. Clone the MySK API repository from GitHub by running the following:

$ git clone https://github.com/suankularb-wittayalai-school/mysk-api.git

Environment Variables

Environment files are used to store sensitive information such as secrets, database URLs, and other important configuration parameters. These files should never be pushed to the repository and are to be kept private.

  1. Navigate into the mysk-api directory. There should be a file called .env.example present and should contain the following:

.env.example
DATABASE_URL=
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
HOST=
PORT=
ROOT_URI=
TOKEN_MAXAGE=
TOKEN_SECRET=
What do these environment variables mean?
  • DATABASE_URL: This one should be self-explanatory, the PostgreSQL database URL that the API will use to connect to. It will contain both the username and password, so it should be kept secret!

  • GOOGLE_OAUTH_CLIENT_ID: This one contains the Google OAuth client ID, used for initiating OAuth with Google.

  • GOOGLE_OAUTH_CLIENT_SECRET: This one contains the Google OAuth client secret, used for exchanging the authorization code during OAuth with Google. As the name suggests, it should be kept secret!

  • HOST: This one contains the IP address (both IPv4 and IPv6 are accepted) that the server will listen on.

  • PORT: This one contains the port number that the server will listen on.

  • ROOT_URI: This one contains the IP address or the domain that Google OAuth will redirect clients back to after authorization. Note that in most cases, this should be set to the same value as the HOST variable if running the server while in development.

  • TOKEN_MAXAGE: This one contains an integer indicating the time until an authorization token expires after issuing in minutes.

  • TOKEN_SECRET: This one contains a secure, randomly generated value that is used to cryptographically sign the HMAC part of the authorization (JWT) token.

  1. Copy the contents from the .env.example file and put it into a new file. Name the new file as .env and put it in the root of the repository.

  2. A senior member of the backend team should have provided you with the environment variables that are secretive, and you can fill out the rest for yourself.

Running MySK API

Open your preferred terminal application in the root of the repository, and run the following command to start the MySK API server in debug/development mode:

$ cargo run

After taking a few minutes to compile, the server should be up and running smoothly!

Last updated