1 /**
2 	Application entry point for a UserMan REST server and web admin frontend.
3 
4 	Use a local "settings.json" file to configure the server.
5 
6 	Copyright: © 2012-2015 RejectedSoftware e.K.
7 	License: Subject to the terms of the General Public License version 3, as written in the included LICENSE.txt file.
8 	Authors: Sönke Ludwig
9 */
10 module app;
11 
12 import vibe.core.args;
13 import vibe.core.core;
14 import vibe.core.log;
15 import vibe.http.fileserver;
16 import vibe.http.router;
17 import vibe.http.server;
18 
19 import userman.api;
20 import userman.db.controller;
21 import userman.webadmin;
22 
23 shared static this()
24 {
25 	ushort restport = 0;
26 	string restintf = "127.0.0.1";
27 	ushort webport = 0;
28 	string webintf = "127.0.0.1";
29 	readOption("admin-port", &webport, "TCP port to listen use for a web admin interface.");
30 	readOption("admin-intf", &webintf, "Network interface address to use for the web admin interface (127.0.0.1 by default)");
31 	readOption("rest-port", &restport, "TCP port to listen for REST API requests.");
32 	readOption("rest-intf", &restintf, "Network interface address to use for the REST API server (127.0.0.1 by default)");
33 
34 	// TODO: read settings.json
35 
36 	if (!restport && !webport) {
37 		logInfo("Neither -rest-port, nor -web-port specified. Exiting.");
38 		logInfo("Run with --help to get a list of possible command line options.");
39 		runTask({ exitEventLoop(); });
40 		return;
41 	}
42 
43 	auto usettings = new UserManSettings;
44 	usettings.requireActivation = false;
45 	usettings.databaseURL = "file://./testdb/";
46 
47 	auto uctrl = createUserManController(usettings);
48 	auto api = createLocalUserManAPI(uctrl);
49 
50 
51 	if (webport) {
52 		auto router = new URLRouter;
53 		router.registerUserManWebAdmin(api);
54 		//router.registerUserManRestInterface(uctrl);
55 		router.get("*", serveStaticFiles("public/"));
56 
57 		auto settings = new HTTPServerSettings;
58 		settings.bindAddresses = [webintf];
59 		settings.sessionStore = new MemorySessionStore;
60 		settings.port = webport;
61 		listenHTTP(settings, router);
62 	}
63 
64 	if (restport) {
65 		auto router = new URLRouter;
66 		router.registerUserManRestInterface(uctrl);
67 
68 		auto settings = new HTTPServerSettings;
69 		settings.bindAddresses = [restintf];
70 		settings.port = restport;
71 		listenHTTP(settings, router);
72 	}
73 }