-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathapp.js
More file actions
27 lines (22 loc) · 700 Bytes
/
app.js
File metadata and controls
27 lines (22 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import http from 'http';
import https from "https";
import fs from "fs";
import app from './api/proxy.js';
const PORT = process.env.PORT || 443;
// 证书路径
const PRIVATE_KEY = "./certs/key.pem";
const CERT_CHAIN = "./certs/cert.pem";
// 证书
let credentials = null;
try {
credentials = {
key: fs.readFileSync(PRIVATE_KEY, 'utf8'),
cert: fs.readFileSync(CERT_CHAIN, 'utf8')
};
} catch (_) {
console.log("No SSL certificate provided, using HTTP.");
}
const server = credentials ? https.createServer(credentials, app) : http.createServer(app);
server.listen(PORT, () => {
console.log(`Proxy server is running on port ${PORT}`);
});