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

[Add] 2주차 세미나 과제 완료 #5

Merged
merged 6 commits into from
Apr 16, 2022
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
11 changes: 11 additions & 0 deletions assignment2/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"watch": [
"src",
".env"
],
"ext": "js,ts,json",
"ignore": [
"src/**/*.spec.ts"
],
"exec": "ts-node --transpile-only ./src/index.ts"
}
18 changes: 18 additions & 0 deletions assignment2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "assignment2",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon",
"build": "tsc && node dist"
},
"dependencies": {
"express": "^4.17.3"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^17.0.24",
"nodemon": "^2.0.15"
}
}
9 changes: 9 additions & 0 deletions assignment2/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express, { Router } from "express";

const router: Router = express.Router();

router.use("/auth", require("./routes/auth"));
router.use("/blog", require("./routes/blog"));
router.use("/user", require("./routes/user"));

module.exports = router;
7 changes: 7 additions & 0 deletions assignment2/src/api/routes/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import express, { Router } from "express";

const router: Router = express.Router();

router.use("/signup", require("./signup"));

module.exports = router;
12 changes: 12 additions & 0 deletions assignment2/src/api/routes/auth/signup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express, { Request, Response, Router } from "express";

const router: Router = express.Router();

router.get("/", (req: Request, res: Response) => {
return res.status(200).json({
status: 200,
message: "로그인 성공, 나도 post하고 싶다.",
});
});

module.exports = router;
7 changes: 7 additions & 0 deletions assignment2/src/api/routes/blog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import express, { Router } from "express";

const router: Router = express.Router();

router.use("/", require("./like"));

module.exports = router;
15 changes: 15 additions & 0 deletions assignment2/src/api/routes/blog/like.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express, { Request, Response, Router } from "express";

const router: Router = express.Router();

router.get("/:postId/like/:likeCount", (req: Request, res: Response) => {
const postId = req.params.postId;
const likeCount = req.params.likeCount;
return res.status(200).json({
status: 200,
message: "좋아요 성공",
data: { postId: postId, likeCount: likeCount },
});
});

module.exports = router;
12 changes: 12 additions & 0 deletions assignment2/src/api/routes/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express, { Request, Response, Router } from "express";

const router: Router = express.Router();

router.get("/", (req: Request, res: Response) => {
return res.status(200).json({
status: 200,
message: "유저 조회 성공",
});
});

module.exports = router;
14 changes: 14 additions & 0 deletions assignment2/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import express, { Request, Response, NextFunction } from "express";

const app = express();

app.use(express.json());
app.use("/api", require("./api"));

app.get("/", (req: Request, res: Response, next: NextFunction) => {
res.send("최상단 루트 엔드포인트");
});

app.listen("8080", () => {
console.log(`8080번 포트 돌아가냐?`);
});
28 changes: 28 additions & 0 deletions assignment2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es6", // 어떤 버전으로 컴파일
"allowSyntheticDefaultImports": true, // default export가 없는 모듈에서 default imports를 허용
"experimentalDecorators": true, // decorator 실험적 허용
"emitDecoratorMetadata": true, // 데코레이터가 있는 선언에 대해 특정 타입의 메타 데이터를 내보내는 실험적인 지원
"skipLibCheck": true, // 정의 파일 타입 체크 여부
"moduleResolution": "node", // commonJS -> node 에서 동작
"module": "commonjs", // import 문법
"strict": true, // 타입 검사 엄격하게
"pretty": true, // error 메시지 예쁘게
"sourceMap": true, // 소스맵 파일 생성 -> .ts가 .js 파일로 트랜스 시 .js.map 생성
"outDir": "./dist", // 트랜스 파일 (.js) 저장 경로
"allowJs": true, // js 파일 ts에서 import 허용
"esModuleInterop": true, // ES6 모듈 사양을 준수하여 CommonJS 모듈을 가져올 수 있게 허용
"typeRoots": [
"./src/types/express.d.ts", // 타입(*.d.ts)파일을 가져올 디렉토리 설정
"./node_modules/@types" // 설정 안할시 기본적으로 ./node_modules/@types
]
},
"include": [
"./src/**/*" // build 시 포함
],
"exclude": [
"node_modules", // build 시 제외
"tests"
]
}
Loading