Files
mixly3/static-server/static-sslserver.js
2024-07-19 10:16:00 +08:00

28 lines
936 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const https = require('https');
const express = require('express');
const fs = require('fs');
const path = require('path');
const SSLStaticServer = {};
SSLStaticServer.run = (port) => {
const KEY_PATH = path.resolve(__dirname, './certs/server.key');
const CRT_PATH = path.resolve(__dirname, './certs/server.crt');
const options = {
key: fs.readFileSync(KEY_PATH),
cert: fs.readFileSync(CRT_PATH)
};
const app = express();
app.use(express.static(path.resolve(__dirname, '../')));
const httpsServer = https.createServer(options, app);
httpsServer.listen(port);
console.log('Static服务器正在运行 [端口 - ' + port + ', https]...');
console.log('访问地址https://127.0.0.1:' + port);
SSLStaticServer.server = httpsServer;
SSLStaticServer.app = app;
SSLStaticServer.port = port;
SSLStaticServer.protocol = 'https';
}
module.exports = SSLStaticServer;