REST API for managing tutorials with user authentication using JWT and user CI/CD.
- User auth (signup/signin) with JWT Bearer Token.
- CRUD tutorials (admin role required for create/update/delete).
- User-Tutorial relationship via
userid
. - Swagger UI for API documentation.
- Node.js, Express, TypeScript
- Sequelize, MySQL
- Swagger, JWT
- Node.js: v18 or higher (if not using Docker).
- MySQL: v8.0 or higher (if not using Docker).
- Docker: For containerized setup.
- Clone:
git clone https://github.com/TranKiemHieu/Mysql.git
- Install:
npm install
- Setup
.env
:DB_HOST=localhost DB_USER=root DB_PASSWORD=yourpassword DB_NAME=testdb JWT_SECRET=your-secret-key PORT=8080
- Create DB:
CREATE DATABASE testdb;
- Build:
npm run build
- Run:
npm run start
- Clone:
git clone https://github.com/TranKiemHieu/Mysql.git
- Ensure Docker and Docker Compose are installed.
- Build and run:
docker-compose up --build
- Access the app:
- API:
http://localhost:8080
- Swagger UI:
http://localhost:8080/api-docs
- MySQL:
localhost:3306
(user: root, password: 1234)
- API:
docker-compose up
docker-compose up -d
docker-compose down
volumes: ['.:/app']
docker-compose --build
- Swagger UI:
http://localhost:8080/api-docs
- Signup:
POST /api/auth/signup
{ "username": "admin1", "email": "admin1@example.com", "password": "P@ssw0rd!2023", "role": "admin" }
- Signin:
POST /api/auth/signin
{ "username": "admin1", "password": "P@ssw0rd!2023" }
- Create Tutorial (Admin):
POST /api/tutorials
- Header:
Authorization: Bearer <token>
{ "title": "Tutorial 1", "description": "Description", "published": true }
- Header:
- Get User Tutorials:
GET /api/tutorials/user
- Header:
Authorization: Bearer <token>
- Header:
- Secure
JWT_SECRET
in.env
. - Configure CORS for production.
MIT License.