Skip to content

Commit

Permalink
Merge branch 'dev' into #156-move-rooms-to-the-past-room-list-and-cha…
Browse files Browse the repository at this point in the history
…nge-settlestatus-automatically-when-the-participant-is-one
  • Loading branch information
14KGun committed Sep 8, 2023
2 parents dd928dc + fefac31 commit 18d2822
Show file tree
Hide file tree
Showing 102 changed files with 12,043 additions and 17,876 deletions.
20 changes: 13 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# required environment variables
PORT=[back의 port(e.g. 80)]
DB_PATH=[mongoDB path(e.g. mongodb://localhost:27017/local)]
AWS_ACCESS_KEY_ID=[AWS Access key ID]
AWS_SECRET_ACCESS_KEY=[AWS Secret access key]
AWS_S3_BUCKET_NAME=[AWS S3 Bucket name]
AWS_S3_URL=[AWS S3 url(e.g. https://<bucket-name>.s3.<region>.amazonaws.com)]

# optional environment variables
REDIS_PATH=[redis path(e.g. redis://127.0.0.1:6379)]
SESSION_KEY=[세션 비밀번호(임의 값 아무거나 설정하면 된다)]
SESSION_KEY=[세션 관리에 사용되는 키(임의 값 아무거나 설정하면 된다)]
JWT_SECRET_KEY=[JWT 관리에 사용되는 키(임의 값 아무거나 설정하면 된다)]
SPARCSSSO_CLIENT_ID=[스팍스SSO ID]
SPARCSSSO_CLIENT_KEY=[스팍스SSO PW]
FRONT_URL=[front url(e.g. http://localhost:3000)]
AWS_ACCESS_KEY_ID=[AWS Access key ID]
AWS_SECRET_ACCESS_KEY=[AWS Secret access key]
AWS_S3_BUCKET_NAME=[AWS S3 Buck name]
JWT_SECRET_KEY=[JWT SERCRET KEY]
APP_URI_SCHEME=[APP_URI_SCHEME]
CORS_WHITELIST=[CORS 정책에서 허용하는 도메인의 목록(e.g. ["http://localhost:3000"])]
GOOGLE_APPLICATION_CREDENTIALS=[GOOGLE_APPLICATION_CREDENTIALS JSON]
TEST_ACCOUNTS=[스팍스SSO로 로그인시 무조건 테스트로 로그인이 가능한 허용 아이디 목록]
SLACK_REPORT_WEBHOOK_URL=[Slack 웹훅 URL들이 담긴 JSON]
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
},
rules: {
"no-unused-vars": 1,
"mocha/no-mocha-arrows": 0,
},
};
30 changes: 23 additions & 7 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,17 +21,33 @@ jobs:
uses: actions/checkout@v3
with:
submodules: true
- name: Setup Node
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
node-version: 16

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
- id: submodule-local
name: Save local version of submodule
run: echo "ver=`cd sampleGenerator && git log --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
- id: submodule-origin
name: Save origin version of submodule
run: echo "ver=`cd sampleGenerator && git log origin --pretty="%h" -1 && cd ..`" >> $GITHUB_OUTPUT
- name: Check submodule version
if: ${{ steps.submodule-local.outputs.ver != steps.submodule-origin.outputs.ver }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('Please update submodule to the latest version by using \"git submodule update --remote\"')
- name: Install sampleGenerator dependencies from package-lock.json
run: cd sampleGenerator && npm ci && cd ..
run: cd sampleGenerator && pnpm i --force --frozen-lockfile && cd ..
- name: Install taxi-back dependencies from package-lock.json
run: npm ci
run: pnpm i --force --frozen-lockfile
- name: Run unit tests
run: npm test
run: pnpm run test
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
/logs/*.log

# AdminJS 관련 디렉토리
.adminjs
.adminjs
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "sampleGenerator"]
path = sampleGenerator
url = https://github.com/sparcs-kaist/taxiSampleGenerator
branch = main
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ COPY . .

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

# Install requirements
RUN npm ci
RUN pnpm i --force --frozen-lockfile

# Run container
EXPOSE 80
ENV PORT 80
CMD ["npm", "run", "serve"]
CMD ["pnpm", "run", "serve"]

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ $ npm install --save

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

## Backend Route Information
See [Backend Route Documentation](src/route/docs/README.md)
See [Backend Route Documentation](src/routes/docs/README.md)

## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
Expand Down
84 changes: 51 additions & 33 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
// 외부 모듈 require
// 모듈 require
const express = require("express");
const http = require("http");

const cookieParser = require("cookie-parser");
const cors = require("cors");

// 내부 모듈
const security = require("./security");
const { port: httpPort } = require("./loadenv");
const logger = require("./src/modules/logger");
const logAPIAccess = require("./src/modules/logAPIAccess");
const startSocketServer = require("./src/modules/socket");
const { startSocketServer } = require("./src/modules/socket");

// Firebase Admin 초기설정
require("./src/modules/fcm").initializeApp();

// 익스프레스 서버 생성
const app = express();

// [Middleware] request body 파싱
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cors({ origin: true, credentials: true }));

// 세션 및 쿠키
const session = require("./src/middleware/session");
// [Middleware] CORS 설정
app.use(require("./src/middlewares/cors"));

// [Middleware] 세션 및 쿠키
const session = require("./src/middlewares/session");
app.use(session);
app.use(cookieParser());
app.use(require("cookie-parser")());

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

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

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

// 라우터 및 리액트
// /rooms/v2에 요청을 보내는 기존 클라이언트 코드 호환성 유지
app.use("/auth", require("./src/route/auth"));
app.use("/json/logininfo", require("./src/route/logininfo"));
app.use("/users", require("./src/route/users"));
app.use(["/rooms/v2", "/rooms"], require("./src/route/rooms"));
app.use("/chats", require("./src/route/chats"));
app.use("/locations", require("./src/route/locations"));
app.use("/reports", require("./src/route/reports"));
// [Middleware] 모든 요청에 대하여 rate limiting 적용
app.use(require("./src/middlewares/limitRate"));

// [Router] Swagger (API 문서)
app.use("/docs", require("./src/routes/docs"));

// [Middleware] 모든 API 요청에 대하여 origin 검증
app.use(require("./src/middlewares/originValidator"));

// [Router] APIs
app.use("/auth", require("./src/routes/auth"));
app.use("/logininfo", require("./src/routes/logininfo"));
app.use("/users", require("./src/routes/users"));
app.use("/rooms", require("./src/routes/rooms"));
app.use("/chats", require("./src/routes/chats"));
app.use("/locations", require("./src/routes/locations"));
app.use("/reports", require("./src/routes/reports"));
app.use("/notifications", require("./src/routes/notifications"));

// [Middleware] 전역 에러 핸들러. 에러 핸들러는 router들보다 아래에 등록되어야 합니다.
app.use(require("./src/middlewares/errorHandler"));

// express 서버 시작
const serverHttp = http.createServer(app).listen(security.port, () => {
logger.info(`Express 서버가 ${security.port}번 포트에서 시작됨.`);
});
const serverHttp = http
.createServer(app)
.listen(httpPort, () =>
logger.info(`Express 서버가 ${httpPort}번 포트에서 시작됨.`)
);

// socket.io 서버 시작
app.set("io", startSocketServer(serverHttp));

// socket.io 서버 시작 및 app 인스턴스에 저장
app.set("io", startSocketServer(serverHttp, session));
// [Schedule] 스케줄러 시작
require("./src/schedules")(app);
41 changes: 41 additions & 0 deletions loadenv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 환경 변수에 따라 .env.production 또는 .env.development 파일을 읽어옴
require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });

module.exports = {
nodeEnv: process.env.NODE_ENV,
mongo: process.env.DB_PATH, // required
session: process.env.SESSION_KEY || "TAXI_SESSION_KEY", // optional
redis: process.env.REDIS_PATH, // optional
sparcssso: {
id: process.env.SPARCSSSO_CLIENT_ID || "", // optional
key: process.env.SPARCSSSO_CLIENT_KEY || "", // optional
},
port: process.env.PORT || 80, // optional (default = 80)
corsWhiteList: (process.env.CORS_WHITELIST &&
JSON.parse(process.env.CORS_WHITELIST)) || [true], // optional (default = [true])
aws: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID, // required
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, // required
s3BucketName: process.env.AWS_S3_BUCKET_NAME, // required
s3Url:
process.env.AWS_S3_URL ||
`https://${process.env.AWS_S3_BUCKET_NAME}.s3.ap-northeast-2.amazonaws.com`, // optional
},
jwt: {
secretKey: process.env.JWT_SECRET_KEY || "TAXI_JWT_KEY",
option: {
algorithm: "HS256",
issuer: process.env.FRONT_URL || "http://localhost:3000", // optional (default = "http://localhost:3000")
},
TOKEN_EXPIRED: -3,
TOKEN_INVALID: -2,
},
googleApplicationCredentials:
process.env.GOOGLE_APPLICATION_CREDENTIALS &&
JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS), // optional
testAccounts:
(process.env.TEST_ACCOUNTS && JSON.parse(process.env.TEST_ACCOUNTS)) || [], // optional
slackWebhookUrl: {
report: process.env.SLACK_REPORT_WEBHOOK_URL || "", // optional
},
};
Loading

0 comments on commit 18d2822

Please sign in to comment.