1 2 //////////////////////////////////////////////////////////////////////////////////////////// 3 // Copyright (c) 2012 Christopher Nicholson-Sauls // 4 // // 5 // Permission is hereby granted, free of charge, to any person obtaining a copy of this // 6 // software and associated documentation files (the "Software"), to deal in the // 7 // Software without restriction, including without limitation the rights to use, copy, // 8 // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, // 9 // and to permit persons to whom the Software is furnished to do so, subject to the // 10 // following conditions: // 11 // // 12 // The above copyright notice and this permission notice shall be included in all // 13 // copies or substantial portions of the Software. // 14 // // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // 16 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // 17 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // 18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // 19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // 20 // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // 21 //////////////////////////////////////////////////////////////////////////////////////////// 22 23 /** 24 * 25 */ 26 module zeal.application; 27 28 import vibe.core.core; 29 30 import vibe.http.router; 31 import vibe.http.server; 32 33 import zeal.config; 34 35 import zeal.http.router; 36 37 import zeal.utils.singleton; 38 39 40 /** 41 * 42 */ 43 final class ZealApplication { 44 mixin Singleton; 45 46 47 /** 48 * 49 */ 50 string[] addresses = [ ZealConfig!`address` ]; 51 ushort port = ZealConfig!`port`; 52 53 54 /** 55 * 56 */ 57 final @property ZealRouter router () { 58 if ( m_router is null ) { 59 m_router = ZealRouter(); 60 } 61 return m_router; 62 } 63 64 65 /** 66 * 67 */ 68 final @property HttpServerSettings serverSettings () { 69 if ( m_serverSettings is null ) { 70 m_serverSettings = new HttpServerSettings; 71 } 72 return m_serverSettings; 73 } 74 75 76 /** 77 * 78 */ 79 final void start () { 80 if ( !m_started ) { 81 auto ss = serverSettings; 82 ss.bindAddresses ~= addresses; 83 ss.port = port; 84 85 listenHttp( ss, router ); 86 87 m_started = true; 88 .start(); 89 } 90 } 91 92 private: 93 94 /** 95 * 96 */ 97 ZealRouter m_router; 98 HttpServerSettings m_serverSettings; 99 bool m_started; 100 101 } // end class ZealApplication