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

48
LINES

< > BotCompany Repo | #1029890 // GAIPPBots: Serve static pages

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (3007L/16K).

!7

!include once #1028763 // helper for HttpFromFileSystem
set flag NoNanoHTTPD.

cmodule ServeDir > DynPrintLog {
  !include #1029545 // API for Eleu
  
  switchable File dir;

  O html(virtual Request request) {
    S uri = cast get(request, 'uri);
    HttpFromFileSystem server = new(dir);
    server.serveFile = f -> {
      if (fileHasExtension(f, ".html"))
        ret rewriteHTML(loadTextFile(f));
      ret server.serveFile_base(f);
    };
    ret server.serve(uri);
  }
  
  S rewriteHTML(S html) {
    LS tok = htmlTok(html);
    
    // drop dummy chat bot CSS
    
    listSet(tok, indexOf(tok, [[<link rel="stylesheet" href="css/chatbot.css">]]), "");
    
    // drop dummy chat bot
    
    int iJS = indexOf(tok, [[<script src="js/chatbot.js">]]);
    if (iJS >= 0)
      clearTokens(tok, iJS, findClosingTag(tok, iJS)+1);

    int iOpening = indexOf(tok, [[<div id="body">]]);
    if (iOpening >= 0) {
      clearTokens(tok, iOpening, findClosingTag(tok, iOpening)+1);

      // add real chat bot
      
      int iEndOfBody = indexOfIC(tok, "</body>");
      if (iEndOfBody >= 0)
        tokAppend(tok, iEndOfBody-1, hscriptsrc("https://gaippbots.com/bot/script"));
    }

    ret join(tok);
  }
}

Author comment

Began life as a copy of #1029773

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1029890
Snippet name: GAIPPBots: Serve static pages
Eternal ID of this version: #1029890/5
Text MD5: 8a9c2a6419725fa8a6c6fbfa7deb2d40
Transpilation MD5: 16644726c0b87bba6569784ac6c62205
Author: stefan
Category: javax / networking
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-27 19:13:27
Source code size: 1263 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 240 / 4778
Version history: 4 change(s)
Referenced in: [show references]