1 module skadi.core.kernel; 2 3 import vibe.d; 4 import skadi.core.container; 5 import skadi.core.router; 6 import skadi.utils.dynamic; 7 import skadi.core.namespaces; 8 import std.functional; 9 import std.typetuple; 10 import std.stdio; 11 import std.file; 12 import std.format; 13 import std.traits; 14 15 final class Kernel 16 { 17 ushort port; 18 19 this(ushort port, immutable Namespace[] skadiNamespaces, immutable Service[] skadiServices) 20 { 21 immutable Namespace[] namespaces = skadiNamespaces; 22 immutable Service[] services = skadiServices; 23 this.port = port; 24 } 25 26 void boot() 27 { 28 this.buildContainer(); 29 30 auto settings = new HTTPServerSettings; 31 settings.errorPageHandler = toDelegate(&errorPage); 32 settings.port = port; 33 34 listenHTTP(settings, this.buildRouter()); 35 } 36 37 void buildContainer() 38 { 39 auto containerIoc = Container.getInstance(); 40 /*foreach(Service s; TypeTupleOf!services) { 41 mixin(format( 42 q{ 43 import %s; 44 containerIoc.register!(%s); 45 }, 46 s.path, 47 s.className 48 )); 49 }*/ 50 } 51 52 URLRouter buildRouter() 53 { 54 auto router = new URLRouter; 55 auto settings = new HTTPServerSettings; 56 auto webSettings = new WebInterfaceSettings; 57 58 /*foreach(Namespace i; TypeTupleOf!namespaces) { 59 60 if (i.controllers !is null) { 61 enum Controller [] controllers = i.controllers; 62 63 foreach(Controller controller; TypeTupleOf!controllers) 64 { 65 if (controller.prefix) { 66 webSettings.urlPrefix = controller.prefix; 67 mixin(format( 68 q{ 69 import Application.%s.Controller.%s; 70 router.registerWebInterface(new %s(), webSettings); 71 }, 72 i.bundle, 73 controller.name, 74 controller.name, 75 )); 76 } else { 77 mixin(format( 78 q{ 79 import Application.%s.Controller.%s; 80 router.registerWebInterface(new %s()); 81 }, 82 i.bundle, 83 controller.name, 84 controller.name, 85 )); 86 } 87 } 88 89 } 90 91 }*/ 92 93 return router; 94 } 95 } 96 97 void errorPage(HTTPServerRequest req, HTTPServerResponse res, HTTPServerErrorInfo error) 98 { 99 //res.render!("error.dt", req, error); 100 }