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

16
LINES

< > BotCompany Repo | #1035558 // serveHttpFromWebServable

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

Libraryless. Click here for Pure Java version (12597L/76K).

// function: func(S uri, SS params) -> NanoHTTPD.Response or string
static MyHTTPD serveHttpFromWebServable(int port, WebServable webServable) ctex {
  assertNotNull(+webServable);
  
  MyHTTPD server = new(port);
  server.serveFunction = func(S uri, SS params) {
    var session = nanoHTTPDCurrentSession();
    var req = new WebRequest(session, uri, params);
    ret webServable.html(req);
  };
  
  server.start();
  print("HTTP port " + port + " open exposing " + webServable);
  
  ret server;
}

Author comment

Began life as a copy of #1023279

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035558
Snippet name: serveHttpFromWebServable
Eternal ID of this version: #1035558/3
Text MD5: 452e55b924bf33f1ce36c07e3e03d602
Transpilation MD5: b24c01a7345d3fc8359bf85e709d26ea
Author: stefan
Category: javax / http
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-16 19:23:09
Source code size: 515 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 206
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)