Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > BotCompany Repo | #1027628 // HTTP+HTTPS Server Include for DynModules

JavaX fragment (include) [tags: use-pretranspiled]

1  
// needs a function O webServe(S uri, SS params) { ... }
2  
3  
switchable int httpPort = 80;
4  
switchable int httpsPort = 443;
5  
transient autoDispose MyHTTPD httpServer;
6  
transient autoDispose MyHTTPD httpsServer;
7  
transient bool redirectHttpToHttps;
8  
9  
transient new HTTPSpamBlocker1 spamBlocker;
10  
11  
void start_webServers(File keyStore, S passphrase) {
12  
  start_webServers(serveHttps_makeSSLSocketFactory(keyStore, passphrase));
13  
}
14  
15  
void start_webServers(SSLServerSocketFactory sslSocketFactory) ctex {
16  
  if (httpPort != 0) {
17  
    httpServer = new MyHTTPD(httpPort);
18  
    httpServer.enter = lambda0 enter;
19  
    httpServer.serveFunction = func(S uri, SS parms) {
20  
      redirectHttpToHttps && !startsWith(uri, "/.well-known/")
21  
        ? serveRedirect("https://" + serveHttp_domainName()
22  
          + (httpsPort == 443 ? "" : ":" + httpsPort) + uri)
23  
        : webServe(uri, parms)
24  
    };
25  
    httpServer.start();
26  
    print("HTTP server started on port " + httpServer.getPort());
27  
  }
28  
  
29  
  if (httpsPort == 0 || sslSocketFactory == null) ret;
30  
  httpsServer = new MyHTTPD(httpsPort);
31  
  httpsServer.enter = lambda0 enter;
32  
  httpsServer.makeSecure(sslSocketFactory);
33  
  httpsServer.serveFunction = func(S uri, SS parms) { webServe(uri, parms) };
34  
  httpsServer.start();
35  
  print("HTTPS server started on port " + httpsServer.getPort());
36  
}

Author comment

Began life as a copy of #1026245

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027628
Snippet name: HTTP+HTTPS Server Include for DynModules
Eternal ID of this version: #1027628/13
Text MD5: 448e968fbaf4b5c3058e9db60e276d7d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-05 13:22:33
Source code size: 1342 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 238 / 1127
Version history: 12 change(s)
Referenced in: [show references]