Skip to content

Commit

Permalink
2주차 세미나
Browse files Browse the repository at this point in the history
  • Loading branch information
RinRinPARK committed Oct 8, 2022
1 parent 8f29be1 commit 583d96f
Show file tree
Hide file tree
Showing 20 changed files with 2,359 additions and 0 deletions.
1 change: 1 addition & 0 deletions seminar1/assignment/SuRin
Submodule SuRin added at 16da1e
6 changes: 6 additions & 0 deletions seminar2-assignment/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"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 seminar2-assignment/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "seminar2-assignment",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon",
"build": "tsc && node dist"
},
"dependencies": {
"express": "^4.18.1"
},
"devDependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.8.3",
"nodemon": "^2.0.20"
}
}
12 changes: 12 additions & 0 deletions seminar2-assignment/src/api/blog.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: "blog 라우터지렁이",
});
});

module.exports = router;
12 changes: 12 additions & 0 deletions seminar2-assignment/src/api/comment.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: "comment 라우터지렁이",
});
});

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

const router: Router = express.Router(); // express 라우팅 시스템을 받아올거!

router.use("/user", require("./user"));
router.use("/blog", require("./blog"));
router.use("/comment", require("./comment"));
router.use("/movie", require("./movie"));
router.use("/members", require("./members"));

module.exports = router; // 모듈로 반환
33 changes: 33 additions & 0 deletions seminar2-assignment/src/api/members.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import express, { Request, Response, Router } from "express";

const router: Router = express.Router();

const members = [{
name: "권세훈",
group: "ob",
},
{
name: "박수린",
group: "yb",
},
{
name: "남지윤",
group: "ob",
},
{
name: "김혜수",
group: "ob",
},
{
name: "이종현",
group: "ob",
}]

router.get("/", (req: Request, res: Response) => {
return res.status(200).json({
status: 200,
members
});
});

module.exports = router;
12 changes: 12 additions & 0 deletions seminar2-assignment/src/api/movie.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: "movie 라우터지렁이",
});
});

module.exports = router;
13 changes: 13 additions & 0 deletions seminar2-assignment/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import express, { Request, Response, Router } from "express";
// express 모듈에서 express, (request, response, router)-> 타입 정의를 위해 불러옴!

const router: Router = express.Router();

router.get("/", (req: Request, res: Response) => {
return res.status(200).json({
status: 200,
message: "user 라우터지렁이",
});
});

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

const app = express(); // express 객체 받아옴
const PORT = 3000; // 사용할 port를 3000번으로 설정

app.use(express.json()); // express 에서 request body를 json 으로 받아오겠다.

app.use("/api", require("./api")); // use -> 모든 요청
// localhost:8000/api -> api 폴더
// localhost:8000/api/user -> user.ts

//* HTTP method - GET
app.get("/", (req: Request, res: Response, next: NextFunction) => {
res.send("서버지렁이");
});

app.listen(PORT, () => {
console.log(`
#############################################
🛡️ Server listening on port: ${PORT} 🛡️
#############################################
`);
}); // 8000 번 포트에서 서버를 실행하겠다!
28 changes: 28 additions & 0 deletions seminar2-assignment/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

0 comments on commit 583d96f

Please sign in to comment.