Skip to content

Commit

Permalink
ec2 version ecr
Browse files Browse the repository at this point in the history
  • Loading branch information
bakgom123 committed Dec 11, 2024
1 parent 03c2782 commit 9b07f23
Show file tree
Hide file tree
Showing 67 changed files with 15,613 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Deploy to ECR

on:
push:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and push Backend Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: community-backend # ECR 백엔드 리포지토리 이름
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./backend
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Build and push Frontend Docker image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: community-frontend # ECR 프론트엔드 리포지토리 이름
IMAGE_TAG: latest
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./frontend
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Dependencies
node_modules/
**/node_modules/

# Environment
.env
**/.env
.env.local
.env.development
.env.production

# Logs
logs
*.log
npm-debug.log*

# Build
build/
dist/

# IDE
.idea/
.vscode/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db
28 changes: 28 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Node.js
node_modules/
npm-debug.log

# IDEs
.vscode/
.idea/
*.sublime-project
*.sublime-workspace

# Operating System Files
.DS_Store

# Logs
*.log

# Build directories
dist/
build/
out/

# Environment variables
.env
.env.local

# Other
*.swp
*.bak
10 changes: 10 additions & 0 deletions backend/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/

package.json
package-lock.json
yarn-error.json
yarn.lock

*.md

*.log
117 changes: 117 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# 2-david-yoo-community-be

# 커뮤니티 게시판 프로젝트 Backend

## 프로젝트 소개
게시판 기능을 제공하는 서버입니다. Express.js와 MariaDB를 기반으로 구현되었으며, 사용자 인증, 게시글 관리, 댓글, 좋아요 등 다양한 기능을 제공합니다.

## 기술 스택
<div style="display:flex;gap:30px;flex-wrap:wrap;">
<img src="https://img.shields.io/badge/-Node.js-339933?style=flat&logo=nodedotjs&logoColor=white"/>
<img src="https://img.shields.io/badge/-Amazon RDS-527FFF?style=flat&logo=amazonrds&logoColor=white"/>
<img src="https://img.shields.io/badge/Express-000000?style=flat-square&logo=Express&logoColor=white"/>
<img src="https://img.shields.io/badge/MariaDB-003545?style=flat-square&logo=mariaDB&logoColor=white"/>
</div>

- **Backend**
- Node.js
- Express.js

- **데이터베이스**
- MariaDB

- **인증**
- express-session
- bcrypt (비밀번호 암호화)

- **파일 처리**
- Multer (파일 업로드)
- Base64 이미지 처리

## 주요 기능
- **사용자 관리**
- 회원가입/로그인/로그아웃
- 프로필 이미지 업로드
- 닉네임 변경
- 비밀번호 변경
- 회원 탈퇴

- **게시글**
- 게시글 CRUD
- 이미지 업로드
- 조회수 관리
- 페이지네이션

- **댓글**
- 댓글 CRUD
- 작성자 정보 표시

- **좋아요**
- 게시글 좋아요/취소
- 좋아요 상태 확인


## 설치 방법

1. 저장소 클론
```bash
git clone https://github.com/100-hours-a-week/2-david-yoo-community-be.git
```

2. 의존성 설치
```bash
npm install
```

3. 환경 변수 설정
`.env` 파일을 생성하고 다음 내용을 설정하세요:
```env
PORT=3000
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
SESSION_SECRET=
```


4. 서버 실행
```bash
npm start
```

## API 엔드포인트

### 인증
- `POST /auth/signup` - 회원가입
- `POST /auth/login` - 로그인
- `POST /auth/logout` - 로그아웃
- `POST /auth/withdraw` - 회원탈퇴

### 사용자
- `PUT /user/nickname` - 닉네임 변경
- `PUT /user/profile-image` - 프로필 이미지 변경
- `GET /user/profile-image/:email` - 프로필 이미지 조회
- `PUT /user/password` - 비밀번호 변경

### 게시글
- `POST /posts` - 게시글 작성
- `GET /posts` - 게시글 목록 조회
- `GET /posts/:id` - 특정 게시글 조회
- `PUT /posts/:id` - 게시글 수정
- `DELETE /posts/:id` - 게시글 삭제

### 댓글
- `POST /api/comments` - 댓글 작성
- `GET /api/comments/:postId` - 댓글 목록 조회
- `PUT /api/comments/:id` - 댓글 수정
- `DELETE /api/comments/:id` - 댓글 삭제

### 좋아요
- `PUT /api/likes/:postId` - 좋아요 상태 변경
- `GET /api/likes/:postId` - 좋아요 상태 확인

### 조회수
- `POST /api/views/:id/increment` - 조회수 증가
- `GET /api/views/:id` - 조회수 조회
76 changes: 76 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import path from 'path';
import express from 'express';
import cors from 'cors';
import session from 'express-session';
import dotenv from 'dotenv';

// 라우트 모듈
import authRoutes from './src/routes/authRoutes.js';
import postRoutes from './src/routes/postRoutes.js';
import userRoutes from './src/routes/userRoutes.js';
import commentRoutes from './src/routes/commentRoutes.js';
import likeRoutes from './src/routes/likeRoutes.js';
import viewRoutes from './src/routes/viewRoutes.js';

// 데이터베이스 설정
import './src/config/database.js';

// Express 앱 초기화 및 환경 설정
const app = express();
const PORT = process.env.PORT || 3000;
dotenv.config();


// 요청 본문 파싱 설정
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ extended: true, limit: '50mb' }));

// 세션 설정
app.use(
session({
secret: process.env.SESSION_SECRET || 'my-secret-key', // 환경변수로 변경 권장
resave: true,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === 'production', // 프로덕션에서만 secure 활성화
maxAge: 24 * 60 * 60 * 1000, // 24시간
sameSite: 'lax',
},
}),
);

// 정적 파일 제공 설정
// CORS 헤더가 포함된 uploads 디렉토리 접근 설정
app.use(
'/uploads',
(req, res, next) => {
// res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:5500');
res.header('Access-Control-Allow-Origin', 'http://43.203.237.161');
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.header(
'Access-Control-Allow-Headers',
'Content-Type, Authorization',
);
next();
},
express.static(path.join(process.cwd(), 'uploads')),
);

// 라우트 설정
app.use('/api/auth', authRoutes);
app.use('/api/posts', postRoutes);
app.use('/api/user', userRoutes);
app.use('/api/comments', commentRoutes);
app.use('/api/likes', likeRoutes);
app.use('/api/views', viewRoutes);

// health check
app.get('/health', (req, res)=>{
res.send('ok');
});

// 서버 시작
app.listen(PORT, () =>
console.log(`✅ Server running at http://localhost:${PORT}`),
);
32 changes: 32 additions & 0 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import { FlatCompat } from '@eslint/eslintrc';
import airbnb from 'eslint-config-airbnb';
import prettier from 'eslint-plugin-prettier';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname, // 필수: 현재 디렉토리 설정
});

export default [
...compat.extends('airbnb'),
...compat.extends('plugin:prettier/recommended'),
{
rules: {
'prettier/prettier': ['error'],
'no-console': 'off',
},
ignores: [
'node_modules/',
'package.json',
'package-lock.json',
'yarn-error.json',
'yarn.lock',
'*.md',
'*.log',
],
},
];
Loading

0 comments on commit 9b07f23

Please sign in to comment.