comparison src/luan/host/WebHandler.java @ 1375:5c3702f60200

cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 11 Jul 2019 23:19:11 -0600
parents 643cf1c37723
children 002152af497a
comparison
equal deleted inserted replaced
1374:72b699bad1a4 1375:5c3702f60200
40 40
41 public static String securityPassword = "password"; // change for security 41 public static String securityPassword = "password"; // change for security
42 private static final DomainHandler domainHandler = new DomainHandler(factory); 42 private static final DomainHandler domainHandler = new DomainHandler(factory);
43 private static String sitesDir = null; 43 private static String sitesDir = null;
44 44
45 public static boolean isServing() {
46 return sitesDir != null;
47 }
48
49 public WebHandler(String dir) { 45 public WebHandler(String dir) {
50 if( sitesDir != null ) 46 if( sitesDir != null )
51 throw new RuntimeException("already set"); 47 throw new RuntimeException("already set");
52 if( !new File(dir).exists() ) 48 if( !new File(dir).exists() )
53 throw new RuntimeException(); 49 throw new RuntimeException();
54 sitesDir = dir; 50 sitesDir = dir;
55 } 51 }
56 52
57 @Override public Response handle(Request request) { 53 @Override public Response handle(Request request) {
58 return domainHandler.handle(request); 54 return domainHandler.handle(request);
59 }
60
61 public static Object runLuan(String domain,String sourceText,String sourceName) throws LuanException {
62 LuanHandler luanHandler = (LuanHandler)domainHandler.getHandler(domain);
63 return luanHandler.runLuan(sourceText,sourceName);
64 } 55 }
65 56
66 public static Object callSite(String domain,String fnName,Object... args) throws LuanException { 57 public static Object callSite(String domain,String fnName,Object... args) throws LuanException {
67 LuanHandler luanHandler = (LuanHandler)domainHandler.getHandler(domain); 58 LuanHandler luanHandler = (LuanHandler)domainHandler.getHandler(domain);
68 return luanHandler.call_rpc(fnName,args); 59 return luanHandler.call_rpc(fnName,args);
86 throw new RuntimeException("couldn't rename "+from+" to "+dir); 77 throw new RuntimeException("couldn't rename "+from+" to "+dir);
87 logger.info("recovered "+name+" from "+from); 78 logger.info("recovered "+name+" from "+from);
88 return true; 79 return true;
89 } 80 }
90 */ 81 */
91 static void initLuan(Luan luan,String dir,String domain,boolean logging) { 82 private static void initLuan(Luan luan,String dir,String domain,boolean logging) {
92 security(luan,dir); 83 security(luan,dir);
93 try { 84 try {
94 LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan"); 85 LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan");
95 fn.call(dir,domain,logging); 86 fn.call(dir,domain,logging);
96 } catch(LuanException e) { 87 } catch(LuanException e) {