Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 새 코드 받아오기
- 제너레이터와 async/await
- 브라우저의 렌더링 과정
- 이벤트
- 딥다이브
- 학습내용정리
- 모던 자바스크립트 Deep Dive
- js pattern
- 이미지 갤러리 최적화
- middleware pattern
- const
- 자바스크립트 패턴
- 프론트엔드 성능 최적화 가이드
- package management
- 자바스크립트 딥다이브
- version management
- 스코프
- peerdependencies
- mixin pattern
- 자바스크립트
- Babel과 Webpack
- 진행기록
- js pattern
- 블로그 서비스 최적화
- 커리어
- 올림픽 통계 서비스 최적화
- pr review
- DOM
- 프로그래머스
- unique identifiers
Archives
- Today
- Total
Dev Blog
Middleware Pattern 본문
실제로 요청과 응답 사이에 위치하는 미들웨어 기능 체인으로,
하나 이상의 미들웨어 함수를 통해 요청 객체부터 응답까지 추적하고 수정할 수 있습니다.
const app = require("express")();
const html = require("./data");
app.use(
"/",
(req, res, next) => {
req.headers["test-header"] = 1234;
next();
},
(req, res, next) => {
console.log(`Request has test header: ${!!req.headers["test-header"]}`);
next();
}
);
app.get("/", (req, res) => {
res.set("Content-Type", "text/html");
res.send(Buffer.from(html));
});
app.listen(8080, function() {
console.log("Server is running on 8080");
});
미들웨어 패턴을 사용하면
모든 통신이 하나의 중앙 지점을 통해 이루어지므로
객체 간의 many to many 관계를 쉽게 단순화할 수 있습니다.
'Development Notes > JS Patterns' 카테고리의 다른 글
Module pattern (0) | 2024.12.08 |
---|---|
Mixin pattern (0) | 2024.12.08 |
Mediator Pattern (0) | 2024.12.08 |
Flyweight Pattern (0) | 2024.12.08 |
Factory Pattern (0) | 2024.12.08 |
Comments