-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from RE-FIT/es6
[refactor]: ES6 모듈 적용
- Loading branch information
Showing
12 changed files
with
552 additions
and
485 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: CD | |
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
branches: ["master"] | ||
|
||
permissions: | ||
contents: read | ||
|
@@ -12,54 +12,53 @@ jobs: | |
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Clear .env file | ||
run: echo "" > .env | ||
- name: Clear .env file | ||
run: echo "" > .env | ||
|
||
- name: Set .env file | ||
run: | | ||
echo "PORT=${{ secrets.PORT }}" >> .env | ||
echo "OAUTH_URL=${{ secrets.OAUTH_URL }}" >> .env | ||
echo "MONGO_DB=${{ secrets.MONGO_DB }}" >> .env | ||
echo "FIREBASE_TYPE=${{ secrets.FIREBASE_TYPE }}" >> .env | ||
echo "FIREBASE_PROJECT_ID=${{ secrets.FIREBASE_PROJECT_ID }}" >> .env | ||
echo "FIREBASE_PRIVATE_KEY_ID=${{ secrets.FIREBASE_PRIVATE_KEY_ID }}" >> .env | ||
echo "FIREBASE_PRIVATE_KEY=${{ secrets.FIREBASE_PRIVATE_KEY }}" >> .env | ||
echo "FIREBASE_CLIENT_EMAIL=${{ secrets.FIREBASE_CLIENT_EMAIL }}" >> .env | ||
echo "FIREBASE_CLIENT_ID=${{ secrets.FIREBASE_CLIENT_ID }}" >> .env | ||
echo "FIREBASE_AUTH_URI=${{ secrets.FIREBASE_AUTH_URI }}" >> .env | ||
echo "FIREBASE_TOKEN_URI=${{ secrets.FIREBASE_TOKEN_URI }}" >> .env | ||
echo "FIREBASE_AUTH_PROVIDER_X509_CERT_URL=${{ secrets.FIREBASE_AUTH_PROVIDER_X509_CERT_URL }}" >> .env | ||
echo "FIREBASE_CLIENT_X509_CERT_URL=${{ secrets.FIREBASE_CLIENT_X509_CERT_URL }}" >> .env | ||
echo "FIREBASE_UNIVERSE_DOMAIN=${{ secrets.FIREBASE_UNIVERSE_DOMAIN }}" >> .env | ||
- name: Set .env file | ||
run: | | ||
echo "PORT=${{ secrets.PORT }}" >> .env | ||
echo "OAUTH_URL=${{ secrets.OAUTH_URL }}" >> .env | ||
echo "MONGO_DB=${{ secrets.MONGO_DB }}" >> .env | ||
echo "FIREBASE_TYPE=${{ secrets.FIREBASE_TYPE }}" >> .env | ||
echo "FIREBASE_PROJECT_ID=${{ secrets.FIREBASE_PROJECT_ID }}" >> .env | ||
echo "FIREBASE_PRIVATE_KEY_ID=${{ secrets.FIREBASE_PRIVATE_KEY_ID }}" >> .env | ||
echo "FIREBASE_PRIVATE_KEY=${{ secrets.FIREBASE_PRIVATE_KEY }}" >> .env | ||
echo "FIREBASE_CLIENT_EMAIL=${{ secrets.FIREBASE_CLIENT_EMAIL }}" >> .env | ||
echo "FIREBASE_CLIENT_ID=${{ secrets.FIREBASE_CLIENT_ID }}" >> .env | ||
echo "FIREBASE_AUTH_URI=${{ secrets.FIREBASE_AUTH_URI }}" >> .env | ||
echo "FIREBASE_TOKEN_URI=${{ secrets.FIREBASE_TOKEN_URI }}" >> .env | ||
echo "FIREBASE_AUTH_PROVIDER_X509_CERT_URL=${{ secrets.FIREBASE_AUTH_PROVIDER_X509_CERT_URL }}" >> .env | ||
echo "FIREBASE_CLIENT_X509_CERT_URL=${{ secrets.FIREBASE_CLIENT_X509_CERT_URL }}" >> .env | ||
echo "FIREBASE_UNIVERSE_DOMAIN=${{ secrets.FIREBASE_UNIVERSE_DOMAIN }}" >> .env | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.16.0 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.16.0 | ||
|
||
- name: Install Dependencies | ||
run: npm ci | ||
- name: Install Dependencies | ||
run: npm ci | ||
|
||
- name: Build App | ||
run: npm run build | ||
- name: Build App | ||
run: npm run build | ||
|
||
- name: Docker Build and Push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -t ${{ secrets.DOCKER_REPO }}/refit-node . | ||
docker push ${{ secrets.DOCKER_REPO }}/refit-node | ||
- name: Deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.KEY }} | ||
script: | | ||
sudo docker rm -f $(docker ps -qa) | ||
sudo docker pull ${{ secrets.DOCKER_REPO }}/refit-node | ||
docker-compose up -d | ||
docker image prune -f | ||
- name: Docker Build and Push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -t ${{ secrets.DOCKER_REPO }}/refit-node . | ||
docker push ${{ secrets.DOCKER_REPO }}/refit-node | ||
- name: Deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.KEY }} | ||
script: | | ||
sudo docker rm -f $(docker ps -qa) | ||
sudo docker pull ${{ secrets.DOCKER_REPO }}/refit-node | ||
docker-compose up -d | ||
docker image prune -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
const mongoose = require('mongoose'); | ||
require('dotenv').config() | ||
import mongoose from "mongoose"; | ||
import dotenv from "dotenv"; | ||
|
||
const connectDB = async () => { | ||
try { | ||
|
||
await mongoose.connect(process.env.MONGO_DB, {useNewUrlParser: true, useUnifiedTopology: true}); | ||
dotenv.config(); | ||
|
||
const db = mongoose.connection; | ||
db.on('error', console.error.bind(console, 'connection error:')); | ||
db.once('open', function() { | ||
console.log("Connected to MongoDB!"); | ||
}); | ||
const connectDB = async () => { | ||
try { | ||
await mongoose.connect(process.env.MONGO_DB, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
|
||
} catch (error) { | ||
console.error('Could not connect to MongoDB!', error); | ||
process.exit(1); | ||
} | ||
const db = mongoose.connection; | ||
db.on("error", console.error.bind(console, "connection error:")); | ||
db.once("open", function () { | ||
console.log("Connected to MongoDB!"); | ||
}); | ||
} catch (error) { | ||
console.error("Could not connect to MongoDB!", error); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
module.exports = connectDB; | ||
export default connectDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
require('dotenv').config(); | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); | ||
|
||
const firebaseConfig = { | ||
type: process.env.FIREBASE_TYPE, | ||
project_id: process.env.FIREBASE_PROJECT_ID, | ||
private_key_id: process.env.FIREBASE_PRIVATE_KEY_ID, | ||
private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'), | ||
client_email: process.env.FIREBASE_CLIENT_EMAIL, | ||
client_id: process.env.FIREBASE_CLIENT_ID, | ||
auth_uri: process.env.FIREBASE_AUTH_URI, | ||
token_uri: process.env.FIREBASE_TOKEN_URI, | ||
auth_provider_x509_cert_url: process.env.FIREBASE_AUTH_PROVIDER_X509_CERT_URL, | ||
client_x509_cert_url: process.env.FIREBASE_CLIENT_X509_CERT_URL, | ||
universe_domain: process.env.FIREBASE_UNIVERSE_DOMAIN | ||
}; | ||
module.exports = firebaseConfig; | ||
type: process.env.FIREBASE_TYPE, | ||
project_id: process.env.FIREBASE_PROJECT_ID, | ||
private_key_id: process.env.FIREBASE_PRIVATE_KEY_ID, | ||
private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, "\n"), | ||
client_email: process.env.FIREBASE_CLIENT_EMAIL, | ||
client_id: process.env.FIREBASE_CLIENT_ID, | ||
auth_uri: process.env.FIREBASE_AUTH_URI, | ||
token_uri: process.env.FIREBASE_TOKEN_URI, | ||
auth_provider_x509_cert_url: process.env.FIREBASE_AUTH_PROVIDER_X509_CERT_URL, | ||
client_x509_cert_url: process.env.FIREBASE_CLIENT_X509_CERT_URL, | ||
universe_domain: process.env.FIREBASE_UNIVERSE_DOMAIN, | ||
}; | ||
|
||
export default firebaseConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,50 @@ | ||
const express = require('express'); | ||
const axios = require('axios'); | ||
const { chat, chatroom } = require('../schemas'); | ||
import express from "express"; | ||
import axios from "axios"; | ||
import { chat, chatroom } from "../schemas.js"; | ||
|
||
const router = express.Router(); | ||
|
||
const resource_url = process.env.OAUTH_URL; | ||
const resource_url = process.env.OAUTH_URL; | ||
|
||
//메시지가 존재하는지 체크하는 메서드 | ||
router.get('/:roomId/check/message', async (req, res) => { | ||
router.get("/:roomId/check/message", async (req, res) => { | ||
const token = req.headers.authorization; // 헤더에서 액세스 토큰 추출 | ||
const roomId = req.params.roomId; // route parameter로부터 roomId를 추출 | ||
|
||
const token = req.headers.authorization; // 헤더에서 액세스 토큰 추출 | ||
const roomId = req.params.roomId; // route parameter로부터 roomId를 추출 | ||
|
||
//엑세스 토큰이 존재하지 않을 경우 | ||
if (!token) { | ||
res.status(400).json({ message: "JWT Token이 존재하지 않습니다.", code: 10100 }); | ||
return; | ||
} | ||
|
||
//리소스에 접급 | ||
try { | ||
const response = await axios.get(resource_url, { | ||
headers: { | ||
'Authorization': `${token}` | ||
} | ||
}); | ||
} catch (error) { | ||
res.status(400).json({ message: "유효하지 않은 JWT Token 입니다.", code: 10101 }); | ||
} | ||
//엑세스 토큰이 존재하지 않을 경우 | ||
if (!token) { | ||
res | ||
.status(400) | ||
.json({ message: "JWT Token이 존재하지 않습니다.", code: 10100 }); | ||
return; | ||
} | ||
|
||
//리소스에 접급 | ||
try { | ||
const response = await axios.get(resource_url, { | ||
headers: { | ||
Authorization: `${token}`, | ||
}, | ||
}); | ||
} catch (error) { | ||
res | ||
.status(400) | ||
.json({ message: "유효하지 않은 JWT Token 입니다.", code: 10101 }); | ||
} | ||
|
||
try { | ||
const chatCount = await chat.exists({ roomId: roomId }); | ||
|
||
try { | ||
const chatCount = await chat.exists({ roomId: roomId }); | ||
|
||
if(chatCount === 0) { | ||
await chatroom.deleteOne({ roomId: roomId }); | ||
res.json({ message: "채팅방이 삭제되었습니다.", code: 200 }); | ||
} else { | ||
res.json({ message: "채팅방에 메시지가 존재합니다.", code: 70002 }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ message: "서버 내부 오류가 발생하였습니다.", code: 50002 }); | ||
if (chatCount === 0) { | ||
await chatroom.deleteOne({ roomId: roomId }); | ||
res.json({ message: "채팅방이 삭제되었습니다.", code: 200 }); | ||
} else { | ||
res.json({ message: "채팅방에 메시지가 존재합니다.", code: 70002 }); | ||
} | ||
}); | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ message: "서버 내부 오류가 발생하였습니다.", code: 50002 }); | ||
} | ||
}); | ||
|
||
module.exports = router; | ||
export default router; |
Oops, something went wrong.