NodeJS http에서 https로 변경하기

sangeun jo·2021년 10월 10일
0

1. mkcert 설치하기

2. 키파일 생성

$ mkcert -install
$ mkcert "localhost" 127.0.0.1 ::1

3. app.py 모듈 임포트

const https = require('https');
const fs = require("fs");

4. app.py 옵션 셜정(키파일 임포트)

const options = {
  key: fs.readFileSync('../keys/localhost-key.pem'),
  cert: fs.readFileSync('../keys/localhost.pem'),
}

5. https로 서버 시작

//app.listen(port, () => console.log(`Listening on port ${port}`));
https.createServer(options,app).listen(port, () => {
    console.log(`Listening on port ${port}`);
});
profile
코더가 아니라 개발자가 되자

0개의 댓글