Uses 911K of libraries. Click here for Pure Java version (3007L/16K).
1 | !7 |
2 | |
3 | !include once #1028763 // helper for HttpFromFileSystem |
4 | set flag NoNanoHTTPD. |
5 | |
6 | cmodule ServeDir > DynPrintLog { |
7 | !include #1029545 // API for Eleu |
8 | |
9 | switchable File dir; |
10 | |
11 | O html(virtual Request request) { |
12 | S uri = cast get(request, 'uri); |
13 | HttpFromFileSystem server = new(dir); |
14 | server.serveFile = f -> { |
15 | if (fileHasExtension(f, ".html")) |
16 | ret rewriteHTML(loadTextFile(f)); |
17 | ret server.serveFile_base(f); |
18 | }; |
19 | ret server.serve(uri); |
20 | } |
21 | |
22 | S rewriteHTML(S html) { |
23 | LS tok = htmlTok(html); |
24 | |
25 | // drop dummy chat bot CSS |
26 | |
27 | listSet(tok, indexOf(tok, [[<link rel="stylesheet" href="css/chatbot.css">]]), ""); |
28 | |
29 | // drop dummy chat bot |
30 | |
31 | int iJS = indexOf(tok, [[<script src="js/chatbot.js">]]); |
32 | if (iJS >= 0) |
33 | clearTokens(tok, iJS, findClosingTag(tok, iJS)+1); |
34 | |
35 | int iOpening = indexOf(tok, [[<div id="body">]]); |
36 | if (iOpening >= 0) { |
37 | clearTokens(tok, iOpening, findClosingTag(tok, iOpening)+1); |
38 | |
39 | // add real chat bot |
40 | |
41 | int iEndOfBody = indexOfIC(tok, "</body>"); |
42 | if (iEndOfBody >= 0) |
43 | tokAppend(tok, iEndOfBody-1, hscriptsrc("https://gaippbots.com/bot/script")); |
44 | } |
45 | |
46 | ret join(tok); |
47 | } |
48 | } |
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: | 242 / 4781 |
Version history: | 4 change(s) |
Referenced in: | [show references] |