forked from rtonservice/simple-reverse-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.js
More file actions
57 lines (47 loc) · 1.79 KB
/
Server.js
File metadata and controls
57 lines (47 loc) · 1.79 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const path = require('path');
const fs = require('fs');
const https = require('https');
const http = require('http');
const compression = require('compression');
const rateLimit = require('express-rate-limit');
// Import Main App
const app = require(path.join(__dirname, 'MainApp.js'));
// Middleware global compression
app.use(compression());
// Middleware rate limit (100 req per 10 detik per IP)
const limiter = rateLimit({
windowMs: 10 * 1000, // 10 detik
max: 100, // Maks 100 request
message: "Too many requests, please slow down."
});
app.use(limiter);
// HTTPS Options
const httpsOptions = {
key: fs.readFileSync(path.join(__dirname, 'certs', '_.growplus.asia', 'cdn.growplus.asia-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'certs', '_.growplus.asia', 'cdn.growplus.asia-crt.pem')),
ca: fs.readFileSync(path.join(__dirname, 'certs', '_.growplus.asia', 'cdn.growplus.asia-chain.pem')),
// Waktu koneksi
requestTimeout: 30000, // 30 detik
keepAliveTimeout: 10000 // 10 detik
};
// Start HTTPS Server on Port 444
const httpsServer = https.createServer(httpsOptions, app);
httpsServer.listen(444, () => {
console.log("HTTPS Server with SNI support started on port 444");
});
httpsServer.on('tlsClientError', (err, socket) => {
console.error("HTTPS TLS Client Error:", err.message);
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
httpsServer.on('clientError', (err, socket) => {
console.error("HTTPS Client Error:", err.message);
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
httpsServer.on('error', (err) => {
console.error("HTTPS Server Error:", err.message);
});
// HTTP fallback for debugging or local
const httpPort = 88;
http.createServer(app).listen(httpPort, () => {
console.log(`HTTP Server started on port ${httpPort}`);
});