Skip to content

Instantly share code, notes, and snippets.

@fredchu
Created May 29, 2023 07:04
Show Gist options
  • Save fredchu/5412699a0bbdee534b56b7f512a7136c to your computer and use it in GitHub Desktop.
Save fredchu/5412699a0bbdee534b56b7f512a7136c to your computer and use it in GitHub Desktop.
// 引入所需的模組
const https = require('https');
const fs = require('fs');
const winston = require('winston');
// 創建 Winston 日誌紀錄器
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'logs/request.log' })
]
});
// 讀取 SSL 證書和密鑰,創建 HTTPS 伺服器
const options = {
key: fs.readFileSync('path/to/key.pem'),
cert: fs.readFileSync('path/to/cert.pem')
};
https.createServer(options, (req, res) => {
// 紀錄詳細的請求資訊到日誌檔案
logger.info({
method: req.method,
url: req.url,
headers: req.headers
});
res.writeHead(200);
res.end('Hello, HTTPS!\n');
}).listen(443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment