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]

// needs a function O webServe(S uri, SS params) { ... }

switchable int httpPort = 80;
switchable int httpsPort = 443;
transient autoDispose MyHTTPD httpServer;
transient autoDispose MyHTTPD httpsServer;
transient bool redirectHttpToHttps;

transient new HTTPSpamBlocker1 spamBlocker;

void start_webServers(File keyStore, S passphrase) {
  start_webServers(serveHttps_makeSSLSocketFactory(keyStore, passphrase));
}

void start_webServers(SSLServerSocketFactory sslSocketFactory) ctex {
  if (httpPort != 0) {
    httpServer = new MyHTTPD(httpPort);
    httpServer.enter = lambda0 enter;
    httpServer.serveFunction = func(S uri, SS parms) {
      redirectHttpToHttps && !startsWith(uri, "/.well-known/")
        ? serveRedirect("https://" + serveHttp_domainName()
          + (httpsPort == 443 ? "" : ":" + httpsPort) + uri)
        : webServe(uri, parms)
    };
    httpServer.start();
    print("HTTP server started on port " + httpServer.getPort());
  }
  
  if (httpsPort == 0 || sslSocketFactory == null) ret;
  httpsServer = new MyHTTPD(httpsPort);
  httpsServer.enter = lambda0 enter;
  httpsServer.makeSecure(sslSocketFactory);
  httpsServer.serveFunction = func(S uri, SS parms) { webServe(uri, parms) };
  httpsServer.start();
  print("HTTPS server started on port " + httpsServer.getPort());
}

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: 239 / 1128
Version history: 12 change(s)
Referenced in: #1027610 - Cruddie standalone [old]
#1027647 - Cruddie [backup with speech recognition on bottom]
#1027648 - Cruddie v2 [moving speech recognition button in chat popup, not really working]
#1027649 - Cruddie v2.1 [just putting the button in the popup]
#1027650 - Cruddie 2.2 [putting everything in one script]
#1027689 - Cruddie [backup before awesomplete]
#1027691 - Cruddie [adding awesomplete, old]
#1027705 - Cruddie [backup before "all public" notice]
#1027715 - Test HttpFromFileSystem
#1027734 - Cruddie [backup before changing cookie handling]
#1028671 - Eleu Cruddie [old]
#1028679 - Cruddie Spike [with VAT magic for Chrome]
#1029492 - HTTP+HTTPS Server Include for DynModules [WebSocket version]
#1029494 - Eleu 3 [backup without WebSockets]
#1029617 - Eleu 3 [backup before DynEleu]