Skip to content

Commit 18d2822

Browse files
committed
Merge branch 'dev' into #156-move-rooms-to-the-past-room-list-and-change-settlestatus-automatically-when-the-participant-is-one
2 parents dd928dc + fefac31 commit 18d2822

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+12043
-17876
lines changed

.env.example

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
# required environment variables
12
PORT=[back의 port(e.g. 80)]
23
DB_PATH=[mongoDB path(e.g. mongodb://localhost:27017/local)]
4+
AWS_ACCESS_KEY_ID=[AWS Access key ID]
5+
AWS_SECRET_ACCESS_KEY=[AWS Secret access key]
6+
AWS_S3_BUCKET_NAME=[AWS S3 Bucket name]
7+
AWS_S3_URL=[AWS S3 url(e.g. https://<bucket-name>.s3.<region>.amazonaws.com)]
8+
9+
# optional environment variables
310
REDIS_PATH=[redis path(e.g. redis://127.0.0.1:6379)]
4-
SESSION_KEY=[세션 비밀번호(임의 값 아무거나 설정하면 된다)]
11+
SESSION_KEY=[세션 관리에 사용되는 키(임의 값 아무거나 설정하면 된다)]
12+
JWT_SECRET_KEY=[JWT 관리에 사용되는 키(임의 값 아무거나 설정하면 된다)]
513
SPARCSSSO_CLIENT_ID=[스팍스SSO ID]
614
SPARCSSSO_CLIENT_KEY=[스팍스SSO PW]
7-
FRONT_URL=[front url(e.g. http://localhost:3000)]
8-
AWS_ACCESS_KEY_ID=[AWS Access key ID]
9-
AWS_SECRET_ACCESS_KEY=[AWS Secret access key]
10-
AWS_S3_BUCKET_NAME=[AWS S3 Buck name]
11-
JWT_SECRET_KEY=[JWT SERCRET KEY]
12-
APP_URI_SCHEME=[APP_URI_SCHEME]
15+
CORS_WHITELIST=[CORS 정책에서 허용하는 도메인의 목록(e.g. ["http://localhost:3000"])]
16+
GOOGLE_APPLICATION_CREDENTIALS=[GOOGLE_APPLICATION_CREDENTIALS JSON]
17+
TEST_ACCOUNTS=[스팍스SSO로 로그인시 무조건 테스트로 로그인이 가능한 허용 아이디 목록]
18+
SLACK_REPORT_WEBHOOK_URL=[Slack 웹훅 URL들이 담긴 JSON]

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ module.exports = {
1010
},
1111
rules: {
1212
"no-unused-vars": 1,
13+
"mocha/no-mocha-arrows": 0,
1314
},
1415
};

.github/workflows/test_ci.yml

+23-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
push:
66
branches: [ "main" ]
77
pull_request:
8-
branches: [ "main" ]
8+
branches: [ "main", "dev" ]
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
@@ -21,17 +21,33 @@ jobs:
2121
uses: actions/checkout@v3
2222
with:
2323
submodules: true
24-
- name: Setup Node
24+
- name: Install Node.js
2525
uses: actions/setup-node@v3
2626
with:
27-
node-version: ${{ matrix.node-version }}
28-
cache: 'npm'
27+
node-version: 16
28+
29+
- uses: pnpm/action-setup@v2
30+
name: Install pnpm
31+
with:
32+
version: 8
33+
- id: submodule-local
34+
name: Save local version of submodule
35+
run: echo "ver=`cd sampleGenerator && git log --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
36+
- id: submodule-origin
37+
name: Save origin version of submodule
38+
run: echo "ver=`cd sampleGenerator && git log origin --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
39+
- name: Check submodule version
40+
if: ${{ steps.submodule-local.outputs.ver != steps.submodule-origin.outputs.ver }}
41+
uses: actions/github-script@v3
42+
with:
43+
script: |
44+
core.setFailed('Please update submodule to the latest version by using \"git submodule update --remote\"')
2945
- name: Install sampleGenerator dependencies from package-lock.json
30-
run: cd sampleGenerator && npm ci && cd ..
46+
run: cd sampleGenerator && pnpm i --force --frozen-lockfile && cd ..
3147
- name: Install taxi-back dependencies from package-lock.json
32-
run: npm ci
48+
run: pnpm i --force --frozen-lockfile
3349
- name: Run unit tests
34-
run: npm test
50+
run: pnpm run test
3551
env:
3652
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
3753
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
/logs/*.log
99

1010
# AdminJS 관련 디렉토리
11-
.adminjs
11+
.adminjs

.gitmodules

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "sampleGenerator"]
22
path = sampleGenerator
33
url = https://github.com/sparcs-kaist/taxiSampleGenerator
4+
branch = main

Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ COPY . .
66

77
# Install curl (for taxi-docker)
88
RUN apk update && apk add curl
9+
RUN npm install --global [email protected] [email protected]
910

1011
# Install requirements
11-
RUN npm ci
12+
RUN pnpm i --force --frozen-lockfile
1213

1314
# Run container
1415
EXPOSE 80
1516
ENV PORT 80
16-
CMD ["npm", "run", "serve"]
17+
CMD ["pnpm", "run", "serve"]
18+

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ $ npm install --save
2929

3030
### Set Environment Configuration
3131
See [notion page](https://www.notion.so/sparcs/Environment-Variables-1b404bd385fa495bac6d5517b57d72bf).
32-
Refer to [.env.example](.env.example) and write your own `.env.development` and `.env.test`.
32+
Refer to [.env.example](.env.example) and write your own `.env`.
3333

3434
## Backend Route Information
35-
See [Backend Route Documentation](src/route/docs/README.md)
35+
See [Backend Route Documentation](src/routes/docs/README.md)
3636

3737
## License
3838
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

app.js

+51-33
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,68 @@
1-
// 외부 모듈 require
1+
// 모듈 require
22
const express = require("express");
33
const http = require("http");
4-
5-
const cookieParser = require("cookie-parser");
6-
const cors = require("cors");
7-
8-
// 내부 모듈
9-
const security = require("./security");
4+
const { port: httpPort } = require("./loadenv");
105
const logger = require("./src/modules/logger");
11-
const logAPIAccess = require("./src/modules/logAPIAccess");
12-
const startSocketServer = require("./src/modules/socket");
6+
const { startSocketServer } = require("./src/modules/socket");
7+
8+
// Firebase Admin 초기설정
9+
require("./src/modules/fcm").initializeApp();
1310

1411
// 익스프레스 서버 생성
1512
const app = express();
13+
14+
// [Middleware] request body 파싱
1615
app.use(express.urlencoded({ extended: false }));
1716
app.use(express.json());
18-
app.use(cors({ origin: true, credentials: true }));
1917

20-
// 세션 및 쿠키
21-
const session = require("./src/middleware/session");
18+
// [Middleware] CORS 설정
19+
app.use(require("./src/middlewares/cors"));
20+
21+
// [Middleware] 세션 및 쿠키
22+
const session = require("./src/middlewares/session");
2223
app.use(session);
23-
app.use(cookieParser());
24+
app.use(require("cookie-parser")());
2425

25-
// API 접근 기록 및 응답 시간을 http response의 헤더에 기록합니다.
26-
app.use(require("response-time")(logAPIAccess));
26+
// [Middleware] Timestamp 및 clientIP 확인
27+
app.use(require("./src/middlewares/information"));
2728

28-
// admin 페이지는 rate limiting을 적용하지 않습니다.
29-
app.use("/admin", require("./src/route/admin"));
29+
// [Middleware] API 접근 기록 및 응답 시간을 http response의 헤더에 기록합니다.
30+
app.use(require("./src/middlewares/responseTime"));
3031

31-
// Apply the rate limiting middleware to all requests
32-
app.use(require("./src/middleware/limitRate"));
32+
// [Router] admin 페이지는 rate limiting을 적용하지 않습니다.
33+
app.use("/admin", require("./src/routes/admin"));
3334

34-
// 라우터 및 리액트
35-
// /rooms/v2에 요청을 보내는 기존 클라이언트 코드 호환성 유지
36-
app.use("/auth", require("./src/route/auth"));
37-
app.use("/json/logininfo", require("./src/route/logininfo"));
38-
app.use("/users", require("./src/route/users"));
39-
app.use(["/rooms/v2", "/rooms"], require("./src/route/rooms"));
40-
app.use("/chats", require("./src/route/chats"));
41-
app.use("/locations", require("./src/route/locations"));
42-
app.use("/reports", require("./src/route/reports"));
35+
// [Middleware] 모든 요청에 대하여 rate limiting 적용
36+
app.use(require("./src/middlewares/limitRate"));
37+
38+
// [Router] Swagger (API 문서)
39+
app.use("/docs", require("./src/routes/docs"));
40+
41+
// [Middleware] 모든 API 요청에 대하여 origin 검증
42+
app.use(require("./src/middlewares/originValidator"));
43+
44+
// [Router] APIs
45+
app.use("/auth", require("./src/routes/auth"));
46+
app.use("/logininfo", require("./src/routes/logininfo"));
47+
app.use("/users", require("./src/routes/users"));
48+
app.use("/rooms", require("./src/routes/rooms"));
49+
app.use("/chats", require("./src/routes/chats"));
50+
app.use("/locations", require("./src/routes/locations"));
51+
app.use("/reports", require("./src/routes/reports"));
52+
app.use("/notifications", require("./src/routes/notifications"));
53+
54+
// [Middleware] 전역 에러 핸들러. 에러 핸들러는 router들보다 아래에 등록되어야 합니다.
55+
app.use(require("./src/middlewares/errorHandler"));
4356

4457
// express 서버 시작
45-
const serverHttp = http.createServer(app).listen(security.port, () => {
46-
logger.info(`Express 서버가 ${security.port}번 포트에서 시작됨.`);
47-
});
58+
const serverHttp = http
59+
.createServer(app)
60+
.listen(httpPort, () =>
61+
logger.info(`Express 서버가 ${httpPort}번 포트에서 시작됨.`)
62+
);
63+
64+
// socket.io 서버 시작
65+
app.set("io", startSocketServer(serverHttp));
4866

49-
// socket.io 서버 시작 및 app 인스턴스에 저장
50-
app.set("io", startSocketServer(serverHttp, session));
67+
// [Schedule] 스케줄러 시작
68+
require("./src/schedules")(app);

loadenv.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// 환경 변수에 따라 .env.production 또는 .env.development 파일을 읽어옴
2+
require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });
3+
4+
module.exports = {
5+
nodeEnv: process.env.NODE_ENV,
6+
mongo: process.env.DB_PATH, // required
7+
session: process.env.SESSION_KEY || "TAXI_SESSION_KEY", // optional
8+
redis: process.env.REDIS_PATH, // optional
9+
sparcssso: {
10+
id: process.env.SPARCSSSO_CLIENT_ID || "", // optional
11+
key: process.env.SPARCSSSO_CLIENT_KEY || "", // optional
12+
},
13+
port: process.env.PORT || 80, // optional (default = 80)
14+
corsWhiteList: (process.env.CORS_WHITELIST &&
15+
JSON.parse(process.env.CORS_WHITELIST)) || [true], // optional (default = [true])
16+
aws: {
17+
accessKeyId: process.env.AWS_ACCESS_KEY_ID, // required
18+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, // required
19+
s3BucketName: process.env.AWS_S3_BUCKET_NAME, // required
20+
s3Url:
21+
process.env.AWS_S3_URL ||
22+
`https://${process.env.AWS_S3_BUCKET_NAME}.s3.ap-northeast-2.amazonaws.com`, // optional
23+
},
24+
jwt: {
25+
secretKey: process.env.JWT_SECRET_KEY || "TAXI_JWT_KEY",
26+
option: {
27+
algorithm: "HS256",
28+
issuer: process.env.FRONT_URL || "http://localhost:3000", // optional (default = "http://localhost:3000")
29+
},
30+
TOKEN_EXPIRED: -3,
31+
TOKEN_INVALID: -2,
32+
},
33+
googleApplicationCredentials:
34+
process.env.GOOGLE_APPLICATION_CREDENTIALS &&
35+
JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS), // optional
36+
testAccounts:
37+
(process.env.TEST_ACCOUNTS && JSON.parse(process.env.TEST_ACCOUNTS)) || [], // optional
38+
slackWebhookUrl: {
39+
report: process.env.SLACK_REPORT_WEBHOOK_URL || "", // optional
40+
},
41+
};

0 commit comments

Comments
 (0)