RouterModule
Express 기반 HTTP 서버를 설정하는 메인 모듈입니다. 미들웨어, 라우팅, Swagger UI, 헬스체크를 자동 구성합니다.
Import
import { RouterModule } from '@asapjs/router';
시그니처
class RouterModule {
public app: express.Application;
constructor(dirname: string);
}
파라미터
| 이름 | 타입 | 설명 |
|---|---|---|
dirname | string | 라우트 파일이 위치한 디렉토리 경로. 이 경로의 route.ts(또는 route.js)를 로드합니다. |
속성
| 이름 | 타입 | 설명 |
|---|---|---|
app | express.Application | Express 애플리케이션 인스턴스 |
자동 구성 내역
미들웨어 (자동 적용)
cors()— CORS 허용bodyParser.json({ limit: '200mb' })— JSON 파싱bodyParser.urlencoded({ limit: '200mb' })— URL-encoded 파싱trust proxy설정- config의
middleware배열에 있는 커스텀 미들웨어
엔드포인트 (자동 등록)
| 경로 | 설명 |
|---|---|
/{basePath} | 서버 상태 확인 |
/health-check | DB 헬스체크 (@asapjs/sequelize 연동) |
/{basePath}/docs/swagger-ui.html | Swagger UI |
/{basePath}/docs/swagger.json | Swagger JSON |
/{basePath}/sync | 모델 동기화 (@asapjs/sequelize 확장) |
Swagger 인증
config에서 Swagger UI 인증을 설정할 수 있습니다:
{
"swagger": {
"useAuth": true,
"userObject": {
"admin": "password"
}
}
}
사용 예제
import { Application } from '@asapjs/core';
import { RouterModule } from '@asapjs/router';
import { initSequelizeModule } from '@asapjs/sequelize';
const app = new Application(__dirname);
await initSequelizeModule(__dirname + '/models');
const router = new RouterModule(__dirname);
router.app.listen(3000, () => {
console.log('Server running on port 3000');
});
route.ts 파일 구조
// src/route.ts
import UserController from './controllers/UserController';
export default [
{ basePath: '/users', router: new UserController().router },
];
관련 API
- RouterController — 컨트롤러 베이스 클래스
- Get / Post / Put / Delete — HTTP 라우트 데코레이터
- jwtVerification — JWT 인증 미들웨어
- HttpException — HTTP 에러 처리