Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junbaehyun 이건 .gitignores에 포함 시켜서 git에서 제거해주세요

Binary file not shown.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 판다마켓 풀스택

## 폴더 구조

### `/api`

Express.js와 Prisma로 구현된 백엔드 프로젝트입니다.
자세한 설명은 `/api/README.md`를 참고해 주세요.

### `/web`

React로 구현된 프론트엔드 프로젝트입니다.
자세한 설명은 `/web/README.md`를 참고해 주세요.
15 changes: 15 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:20.15.1-alpine3.19

ENV DOCKERIZE_VERSION v0.7.0
RUN apk update --no-cache \
&& apk add --no-cache wget openssl \
&& wget -O - https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz | tar xzf - -C /usr/local/bin \
&& apk del wget

WORKDIR /app

EXPOSE 3000

COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
RUN ["chmod", "+x", "./docker-entrypoint.sh"]
ENTRYPOINT ["sh", "./docker-entrypoint.sh"]
134 changes: 134 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

# 판다마켓 백엔드

## 실행하기

### 도커를 통하여 실행하기

도커를 사용하면, 환경에 구애받지 않고 어플리케이션을 쉽게 개발 및 실행할 수 있습니다.

해당 장에서는 도커에 대해 자세하게 설명하지 않습니다.
자세한 사항은 [도커 공식문서](https://docs.docker.com/desktop/)를 참조해주세요.


#### 준비물

- npm
- docker
- cocker-compose

#### 실행하는 방법

```shell
npm run compose
```

docker-compose 를 통해 실행했다면, postgresql 은 도커 내부에 자동적으로 만들어집니다.

아래는 자원의 접근 정보입니다.

**DB**

- `PORT` : 15432 (localhost:15432 으로 접근)
- `USER_NAME` : postgres
- `USER_PASSWORD` : postgres

**Service**

- `PORT` : 13000 (localhost:13000 으로 접근)

그 외에 필요한 환경 변수들은 아래를 참고하여 설정해 주셔야 합니다.


### 로컬 환경에서 실행하기

#### 준비물

- nodejs
- postgresql

#### 실행 전, 필요한 작업

1. `.env` 파일 설정

이미지 업로드시 노출시킬 서버의 주소를 `BASE_URL`로 설정해 주세요. 이때 주소의 마지막에 슬래시(`/`)는 포함하지 않습니다.
서버를 실행할 포트 번호를 `HTTP_PORT`에 원하는 값으로 설정해 주세요. 포트 값을 설정하지 않으면 기본 값은 3000으로 실행됩니다.

```
BASE_URL=http://localhost:3001
HTTP_PORT=3001
```


PostgreSQL 접속정보를 환경변수에 반영해야 합니다.
아래 포맷에 맞추어 `DATABASE_URL` 값을 수정해 주세요.

```
DATABASE_URL=postgresql://{userName}:{password}@{dbHost}:{dbPort}/{dbName}
```

JWT 생성 발급을 위한 시크릿 키와 구글 계정 관련 정보도 설정해 주세요. 이때 CLIENT_REDIRECT_URI는 소셜 로그인을 마치고 인증 토큰을 담은 쿼리 스트링과 함께 클라이언트가 최종 도착할 URI입니다.

```
JWT_ACCESS_TOKEN_SECRET=<사용할 secret key>
JWT_REFRESH_TOKEN_SECRET=<사용할 secret key>
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=
CLIENT_REDIRECT_URI=
```

위에서 필요한 `GOOGLE_CLIENT_*` 값들은 구글 Credentials에서 OAuth 클라이언트를 설정할 때 얻을 수 있습니다.

구글의 Credentials에서 OAuth Client를 생성할 때 `/auth/google/callback` 이라는 경로를 기준으로 허용 승인된 리디렉션 URI를 추가해 주세요.
![설정 화면](./google-auth-setting.png)

2. DB 마이그레이션

서비스를 운영하기 위해 필요한 테이블들을 생성해야 합니다.

- Article
- Product
- Comment

```
npx prisma migrate deploy
```

PostgreSQL 접속정보가 올바르지 않다면 실패할 수 있습니다.


3. DB Seeding (옵션)

```
npm run seed
```

4. 의존성 설치

서비스가 동작하기 위해 필요한 라이브러리를 설치합니다.

```
npm install
```

5. Prisma Client 생성

`@prisma/client` 는 로컬의 `schema.prisma` 파일을 읽어서 만들어지는 패키지입니다.
처음 및 스키마 파일이 변경될 때 마다, 아래 명령어를 실행해주세요.

```
npx prisma generate
```

6. 서비스 실행

```
npm start
```

혹은 개발 중 `nodemon`으로 실행하고 싶다면 아래 명령어를 사용하면 됩니다.

```
npm run dev
```
42 changes: 42 additions & 0 deletions api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '2.2'

services:
pg-db:
image: postgres:16.3-alpine3.19
attach: false
container_name: panda-market-db
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=panda-market
networks:
- panda-market-network
ports:
- '15432:5432'
command: [postgres]

service:
container_name: panda-market-app
build:
context: .
dockerfile: ./Dockerfile
restart: no
environment:
# Application
- NODE_ENV=development
- DATABASE_URL=postgresql://postgres:postgres@pg-db:5432/panda-market
- JWT_ACCESS_TOKEN_SECRET=$3cr3t
- JWT_REFRESH_TOKEN_SECRET=$3cr3t
networks:
- panda-market-network
ports:
- '13000:3000'
volumes:
- .:/app/
depends_on:
- pg-db

networks:
panda-market-network:
name: panda-market-network
7 changes: 7 additions & 0 deletions api/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dockerize -wait tcp://pg-db:5432 -timeout 60s

npx prisma generate
npx prisma migrate deploy
npm run seed

npm start
Binary file added api/google-auth-setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions api/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/nodetouch

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/prettier

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/prisma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/node_modules/.bin/yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading