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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
20 changes: 20 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import express from "express";
import dotenv from "dotenv";
import router from "./routes/index.js";
import cors from "cors";
import cookieParser from "cookie-parser";
dotenv.config();

const port = 8000;
const app = express();
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
app.use(cookieParser());
app.use(express.json());
app.use("/api", router);

app.listen(port, () => console.log(`${port}서버시작`));
37 changes: 37 additions & 0 deletions middlewares/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import userRepository from "../repositories/userRepository.js";
import { expressjwt } from "express-jwt";

export function throwUnauthorizedError() {
const error = new Error("Unauthorized");
error.code = 401;
throw error;
}

async function verifySessionLogin(req, res, next) {
try {
const { userId } = req.session;
if (!userId) throwUnauthorizedError();

const user = await userRepository.findById(userId, {
board: true,
comment: true,
});

next();
} catch (err) {
next(err);
}
}

const verifyAccessToken = expressjwt({
secret: process.env.JWT_SECRET,
algorithms: ["HS256"],
requestProperty: "user",
debug: true, // 디버그 모드 활성화
});

const auth = {
verifySessionLogin,
verifyAccessToken,
};
export default auth;
55 changes: 55 additions & 0 deletions mock/board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"title": "게시판 공지사항",
"content": "이 게시판은 공지사항을 위한 공간입니다.",
"images": [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg"
]
},
{
"title": "오늘의 할일",
"content": "할 일을 정리해서 공유합니다.",
"images": []
},
{
"title": "여행 사진 공유",
"content": "지난 여행에서 찍은 사진입니다.",
"images": ["https://example.com/travel1.jpg"]
},
{
"title": "맛집 추천",
"content": "이번 주말에 갈 만한 맛집을 추천합니다.",
"images": ["https://example.com/food1.jpg", "https://example.com/food2.jpg"]
},
{
"title": "독서 클럽 공지",
"content": "다음 독서 모임 일정 및 책 선정 내용입니다.",
"images": []
},
{
"title": "운동 기록",
"content": "오늘 한 운동을 기록합니다.",
"images": ["https://example.com/workout1.jpg"]
},
{
"title": "개발자 모임 후기",
"content": "지난주 개발자 모임 후기를 공유합니다.",
"images": ["https://example.com/dev1.jpg", "https://example.com/dev2.jpg"]
},
{
"title": "영화 감상 후기",
"content": "최근 본 영화에 대한 감상을 나눕니다.",
"images": []
},
{
"title": "취미 생활 공유",
"content": "최근 새로 시작한 취미입니다.",
"images": ["https://example.com/hobby1.jpg"]
},
{
"title": "다이어트 일지",
"content": "다이어트 진행 상황과 식단을 공유합니다.",
"images": ["https://example.com/diet1.jpg", "https://example.com/diet2.jpg"]
}
]
38 changes: 38 additions & 0 deletions mock/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"email": "[email protected]",
"name": "이름1",
"password": "password123",
"image": "/img/ic_profile.png"
},
{
"email": "[email protected]",
"name": "이름2",
"password": "securepass456",
"image": "/img/ic_profile.png"
},
{
"email": "[email protected]",
"name": "이름3",
"password": "mypassword789",
"image": "/img/custom_image1.png"
},
{
"email": "[email protected]",
"name": "이름4",
"password": "password321",
"image": "/img/custom_image2.png"
},
{
"email": "[email protected]",
"name": "이름5",
"password": "securepassword654",
"image": "/img/ic_profile.png"
},
{
"email": "[email protected]",
"name": "이름6",
"password": "anotherpass987",
"image": "/img/custom_image3.png"
}
]
Loading
Loading