Skip to content

SheathedSharp/Type-Shift-Arena-Backend

Repository files navigation

Type Shi(f)t Arena Backend


This is a backend project for Type Shi(f)t Arena. It is a simple project that uses Spring Boot and Spring Data JPA to manage a MySQL database.

Adding Environment Variables

In the development environment, database and JWT configurations use environment variables to prevent privacy leaks.

The specific code is as follows:

# application-dev.properties
......
spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost:3306/myappdb}
spring.datasource.username=${MYSQL_USERNAME}
spring.datasource.password=${MYSQL_PASSWORD}
.....
.....
jwt.secret=${JWT_SECRET:your_jwt_secret_key_should_be_at_least_256_bits_long_for_security}
jwt.expiration=${JWT_EXPIRATION:86400}

For Windows:

  1. Right-click "This PC" -> Properties
  2. Click "Advanced system settings"
  3. Click "Environment Variables" button
  4. Click "New" in the "System Variables" section
  5. Add the following variables:
MYSQL_USERNAME=your_database_username
MYSQL_PASSWORD=your_password
JWT_SECRET=your_secret_key (optional)
JWT_EXPIRATION=your_desired_expiration_time (optional)

For Mac:

  1. Open configuration file nano ~/.zshrc
  2. Add the following content:
export MYSQL_USERNAME=your_database_username
export MYSQL_PASSWORD=your_password
export JWT_SECRET=your_secret_key (optional)
export JWT_EXPIRATION=your_desired_expiration_time (optional)
  1. Save and exit the file
  2. Reload configuration with source ~/.zshrc

DEPENDENCIES

  • Spring Boot 3.2.3
  • Maven 3.9.9
  • MySQL 9.0.1
  • JDK 17
  • JWT
  • Spring Security
  • Spring WebSocket

Database Setup

To initialize the database, follow these steps:

  1. Ensure you have MySQL installed and running.

  2. Open a MySQL client (e.g., MySQL Workbench or command-line client).

  3. Run the SQL script located at sql/init.sql. This will create the database and necessary tables.

    You can do this by running the following command in your MySQL client:

    source /path/to/your/project/sql/init.sql
    
  4. Update the application-dev.properties and application-prod.properties files with your database credentials.

Running the Application

To run the application, use the following command. (Default is development environment)

for development:

mvn spring-boot:run

for production:

mvn spring-boot:run -Dspring.profiles.active=prod

visit http://localhost:9090/hello to see the result.

API Documentation AND TEST

visit http://localhost:9090/swagger-ui.html to see the API documentation and test the API.

waring: some API may not work because of the security configuration.

About

Type Shi(f)t Arena is an open-source project designed to combine fun and competition in typing practice, while maintaining high-quality code and an excellent user experience.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages