2018-12-18 22:18:06 +01:00
|
|
|
module d_webservice_example.application;
|
|
|
|
|
2019-01-03 03:33:42 +01:00
|
|
|
import aermicioi.aedi : Container, locate, singleton;
|
|
|
|
import vibe.http.router : URLRouter;
|
2018-12-18 22:18:06 +01:00
|
|
|
|
|
|
|
void main() @safe
|
|
|
|
{
|
|
|
|
import d_webservice_example.component_registration : registerComponents;
|
2019-01-03 03:33:42 +01:00
|
|
|
import vibe.core.core : runApplication;
|
|
|
|
import vibe.http.server : HTTPServerSettings, listenHTTP;
|
|
|
|
|
|
|
|
setupLogging;
|
2018-12-18 22:18:06 +01:00
|
|
|
|
2018-12-21 21:22:06 +01:00
|
|
|
auto container = singleton;
|
2018-12-18 22:18:06 +01:00
|
|
|
scope (exit)
|
|
|
|
container.terminate;
|
|
|
|
|
2018-12-21 21:22:06 +01:00
|
|
|
container.registerComponents;
|
2018-12-18 22:18:06 +01:00
|
|
|
container.instantiate;
|
|
|
|
|
|
|
|
auto settings = new HTTPServerSettings;
|
|
|
|
settings.port = 8080;
|
|
|
|
settings.bindAddresses = ["::", "0.0.0.0"];
|
2019-01-03 03:33:42 +01:00
|
|
|
|
|
|
|
auto router = setupRouter(container);
|
2018-12-18 22:18:06 +01:00
|
|
|
listenHTTP(settings, router);
|
|
|
|
|
2018-12-21 21:22:06 +01:00
|
|
|
runApplication;
|
2018-12-18 22:18:06 +01:00
|
|
|
}
|
2019-01-03 03:33:42 +01:00
|
|
|
|
|
|
|
void setupLogging() nothrow @safe
|
|
|
|
{
|
|
|
|
import vibe.core.log : setLogFormat, FileLogger;
|
|
|
|
|
|
|
|
debug
|
|
|
|
{
|
|
|
|
import vibe.core.log : LogLevel, setLogLevel;
|
|
|
|
|
|
|
|
setLogLevel(LogLevel.diagnostic);
|
|
|
|
}
|
|
|
|
setLogFormat(FileLogger.Format.threadTime, FileLogger.Format.threadTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
URLRouter setupRouter(Container container) @safe
|
|
|
|
{
|
|
|
|
import d_webservice_example.controller.todo_controller : TodoController;
|
|
|
|
import d_webservice_example.controller.todo_notification_controller : TodoNotificationController;
|
|
|
|
import vibe.web.rest : registerRestInterface;
|
|
|
|
import vibe.web.web : registerWebInterface;
|
|
|
|
|
|
|
|
auto router = new URLRouter;
|
|
|
|
router.registerRestInterface(container.locate!TodoController);
|
|
|
|
router.registerWebInterface(container.locate!TodoNotificationController);
|
|
|
|
return router;
|
|
|
|
}
|