[Node.js] Swagger UI의 CSS가 안나오는 경우

Gul B.·2023년 8월 18일

위 사진처럼 swagger-UI가 설정은 되었지만 CSS가 로딩이 안된경우

app.use(setUTF8Encoding);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs, { explorer: true }));

요게 문제였다.

setUTF8Encoding.js

const setUTF8Encoding = (req, res, next) => {
    res.setHeader('Content-Type', 'text/html; charset=utf-8');
    next();
};

exports.setUTF8Encoding = setUTF8Encoding;

response를 UTF-8 인코딩하는 미들웨어를 두었었는데. 이게 css파일도 건드렸던 듯하다. 위 코드를 수정하거나

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs, { explorer: true }));
app.use(setUTF8Encoding);

미들웨어 순서를 바꿔준다.

미들웨어가 원인인줄 몰랐다.
난 멀었다

profile
So you want to be a pilot

1개의 댓글

comment-user-thumbnail
2023년 8월 18일

좋은 정보 감사합니다

답글 달기