Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] cookie/token #168

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { specs } from './config/swagger.config.js';
import SwaggerUi from 'swagger-ui-express';
import dotenv from 'dotenv';
import cors from 'cors';
import jwt from 'jsonwebtoken';
import cookieParser from 'cookie-parser';

import { response } from './config/response.js';
import { BaseError } from './config/error.js';
Expand All @@ -26,6 +28,7 @@ import { translateToMP3 } from './src/routes/translateToMP3.route.js';




dotenv.config(); // .env 파일 사용 (환경 변수 관리)

const app = express();
Expand Down Expand Up @@ -66,7 +69,9 @@ app.use(kakaoRoute);
app.use('/search',searchRoute);
app.use('/video', translateToMP3); // script 라우트 적용

app.get('/', (req, res, next) => {
app.use(cookieParser()); // 쿠키 파서 미들웨어

app.get('/', generateTempToken, (req, res, next) => {
res.send(response(status.SUCCESS, "루트 페이지!"));
})

Expand All @@ -91,3 +96,16 @@ app.listen(app.get('port'), () => {
console.log(`Example app listening on port ${app.get('port')}`);
});



// 임시 토큰 생성 및 쿠키 저장 미들웨어
function generateTempToken(req, res, next) {
// 임시 토큰 생성 (여기서는 간단히 예시를 위한 토큰을 생성합니다)
const tempToken = jwt.sign({ user: 'tempUser' }, 'yourSecretKey', { expiresIn: '2h' });

// 쿠키에 토큰 저장
res.cookie('tempToken', tempToken, { httpOnly: true });

next(); // 다음 미들웨어 또는 라우트 핸들러로 제어를 넘깁니다.
}

21 changes: 21 additions & 0 deletions package-lock.json

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

209 changes: 56 additions & 153 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,155 +1,58 @@
{

"name": "vino-server",

"version": "1.0.0",

"description": "",

"main": "index.js",

"scripts": {


"test": "echo \"Error: no test specified\" && exit 1",


"start:dev": "nodemon --exec babel-node index.js",


"start:dist": "webpack --mode production & node ./dist/main.js",


"start": "node main.js",


"build": "webpack --mode production"

},

"author": "",

"license": "ISC",

"dependencies": {


"@ffmpeg-installer/ffmpeg": "^1.1.0",


"@ffprobe-installer/ffprobe": "^2.1.2",


"aws-sdk": "^2.1542.0",


"axios": "^1.6.7",


"bcryptjs": "^2.4.3",


"cors": "^2.8.5",


"dotenv": "^16.4.1",


"express": "^4.18.2",


"express-session": "^1.17.3",


"ffmpeg": "^0.0.4",


"fluent-ffmpeg": "^2.1.2",


"get-youtube-title": "^1.0.1",


"http-status-codes": "^2.3.0",


"install": "^0.13.0",


"jsonwebtoken": "^9.0.2",


"multer": "^1.4.5-lts.1",


"multer-s3": "^2.10.0",


"mysql2": "^3.7.0",


"nodemailer": "^6.9.8",


"openai": "^4.26.0",


"redis": "^4.6.12",


"solapi": "^5.2.4",


"swagger-cli": "^4.0.4",


"swagger-jsdoc": "^6.2.8",


"swagger-ui-express": "^5.0.0",


"youtube-mp3-downloader": "^0.7.11",


"ytdl-core": "^4.11.5"

},

"devDependencies": {


"@babel/cli": "^7.23.4",


"@babel/core": "^7.23.9",


"@babel/node": "^7.23.9",


"@babel/preset-env": "^7.23.7",


"babel-cli": "^6.26.0",


"babel-loader": "^9.1.3",


"nodemon": "^3.0.2",


"swagger": "^0.7.5",


"webpack": "^5.89.0",


"webpack-cli": "^5.1.4",


"webpack-node-externals": "^3.0.0"

}
"name": "vino-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:dev": "nodemon --exec babel-node index.js",
"start:dist": "webpack --mode production & node ./dist/main.js",
"start": "node main.js",
"build": "webpack --mode production"
},
"author": "",
"license": "ISC",
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"@ffprobe-installer/ffprobe": "^2.1.2",
"aws-sdk": "^2.1542.0",
"axios": "^1.6.7",
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"express": "^4.18.2",
"express-session": "^1.17.3",
"ffmpeg": "^0.0.4",
"fluent-ffmpeg": "^2.1.2",
"get-youtube-title": "^1.0.1",
"http-status-codes": "^2.3.0",
"install": "^0.13.0",
"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
"multer-s3": "^2.10.0",
"mysql2": "^3.7.0",
"nodemailer": "^6.9.8",
"openai": "^4.26.0",
"redis": "^4.6.12",
"solapi": "^5.2.4",
"swagger-cli": "^4.0.4",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0",
"youtube-mp3-downloader": "^0.7.11",
"ytdl-core": "^4.11.5"
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.9",
"@babel/node": "^7.23.9",
"@babel/preset-env": "^7.23.7",
"babel-cli": "^6.26.0",
"babel-loader": "^9.1.3",
"nodemon": "^3.0.2",
"swagger": "^0.7.5",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0"
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/controllers/summary.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import getYoutubeTitle from 'get-youtube-title';
export const processVideo = async (req, res) => {
try {
//사용자에게 입력받을 video ID 변수
const token = req.cookies['auth-token'];
const videoId = req.params.videoId;

if(!token) {
return res.status(401).send("비정상 접근입니다.");
}

let videoTitle="";

getYoutubeTitle(videoId,async function(err,title){
videoTitle=title;
})
Expand Down Expand Up @@ -166,7 +173,7 @@ export const speechresult = async (req, res) => {
"text":jsonData.segments[i].text
})
}

console.log("시간데이터 있는 데이터",timeStampData);
console.log(scriptText);

Expand Down
5 changes: 5 additions & 0 deletions src/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export const register = async (req, res) => {
export const login = async (req, res) => {
try {
const response = await loginService(req.body);
if(response.success){
//로그인 성공시 임시 토큰 쿠키 삭제
res.clearCookie('tempToken');
}
return res.status(response.status).json(response);

} catch (error) {
console.log(error);
return res.status(500).json({
Expand Down
Loading