Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ name: CI - Test Docker Compose

on:
push:
branches: [master]
branches:
- master
- Stogare-jwt-and-google-sigin-signout
pull_request:
branches: [master]

jobs:
test-docker-compose:
Expand Down Expand Up @@ -31,7 +34,3 @@ jobs:
run: |
sleep 10
docker logs node-app

- name: Check app is running
run: |
curl --fail http://localhost:3000 || exit 1
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Backend API với TypeScript, Prisma, Docker, JWT và Google OAuth2

## Mô tả dự án

Dự án backend xây dựng bằng **TypeScript**, sử dụng **Prisma ORM** để kết nối và thao tác với cơ sở dữ liệu PostgreSQL. Dự án hỗ trợ xác thực người dùng bằng **JWT** và đăng nhập qua **Google OAuth2**.

Dự án được đóng gói trong Docker container để dễ dàng triển khai và phát triển.

---

## Công nghệ sử dụng

- Node.js & TypeScript
- Prisma ORM (với PostgreSQL)
- Docker & Docker Compose
- JWT Authentication
- Google OAuth2
- Postgres Database

---

## Cách chạy dự án

### Yêu cầu

- Docker & Docker Compose đã được cài đặt
- Node.js (chỉ cần khi bạn muốn chạy local không dùng Docker)

### 1. Cấu hình biến môi trường

Tạo file `.env` trong root dự án với các biến sau:

```env
POSTGRES_URL=postgresql://myuser:mypassword@postgres-db:5432/mydatabase
PORT=3000
GOOGLE_CLIENT_ID=your-google-client-id
JWT_SECRET=your-jwt-secret
```

### 2. Chạy bằng Docker Compose

```bash
docker-compose up -d
```

### 3. Chạy local (không dùng Docker)

```bash
npm install
npx prisma generate
npx tsc
node dist/server.js
```

### API Endpoints chính

| Phương thức | URL | Mô tả |
| ----------- | -------------- | ---------------------------- | --- |
| POST | `/auth/login` | Đăng nhập bằng JWT |
| POST | `/auth/google` | Đăng nhập bằng Google OAuth2 |
| POST | `/auth/logout` | Đăng xuất |
| GET | `/auth/signup` | Đăng kí | |
17 changes: 4 additions & 13 deletions src/routes/index.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ router.get("/favicon.ico", (req: Request, res: Response) => {
res.status(204).end();
});

router.post("/api/signup", registerUser);
router.post(
"/auth/google-login",
verifyGoogleToken,
authController.googleLogin
);
router.post("/api/login", authController.login);
router.post("/auth/signup", registerUser);
router.post("/auth/google", verifyGoogleToken, authController.googleLogin);
router.post("/auth/login", authController.login);

router.post("/api/logout", verifyJwtToken, authController.logout);
// router.put(
// "/api/matchmaking/start",
// verifyJwtToken,
// matchmaking.startMatchmaking
// );
router.post("/auth/logout", verifyJwtToken, authController.logout);

export default router;