1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.core.websettings;
7 
8 import diamond.core.apptype;
9 
10 static if (isWeb)
11 {
12   /// The web settings for the application.
13   private __gshared WebSettings _webSettings;
14 
15   /// The abstract wrapper for web settings.
16   abstract class WebSettings
17   {
18     import vibe.d : HTTPServerRequest, HTTPServerResponse, HTTPServerErrorInfo;
19 
20     import diamond.http.client;
21 
22     protected:
23     /// Creates a new instance of the web settings.
24     this() { }
25 
26     public:
27     /// Function invoked when the application starts.
28     abstract void onApplicationStart();
29 
30     /*
31     * Function invoked before a request has been processed.
32     * Params:
33     *   client =  The client.
34     * Returns:
35     *   True if the request can be processed, false otherwise.
36     */
37     abstract bool onBeforeRequest(HttpClient client);
38 
39     /*
40     * Function invoked after a request has been processed successfully.
41     * Params:
42     *   client =  The client.
43     */
44     abstract void onAfterRequest(HttpClient client);
45 
46     /*
47     * Function invoked when an error has been encountered.
48     * Params:
49     *   thrownError = The error encountered.
50     *   request =     The request.
51     *   response =    The response.
52     *   error =       The error information (this can be null)
53     */
54     abstract void onHttpError
55     (
56       Throwable thrownError, HTTPServerRequest request,
57       HTTPServerResponse response, HTTPServerErrorInfo error
58     );
59 
60     /*
61     * Function invoked when a page or an action cannot be found.
62     * Use request.path to get the path that was attempted to be accessed
63     * Params:
64     *   request =  The request.
65     *   response = The response.
66     */
67     abstract void onNotFound(HTTPServerRequest request, HTTPServerResponse response);
68 
69     /*
70     * Function invoked before a static file is processed.
71     * Params:
72     *   client =  The client.
73     */
74     abstract void onStaticFile(HttpClient client);
75   }
76 
77   @property
78   {
79     /// Gets the web settings.
80     WebSettings webSettings() { return _webSettings; }
81 
82     /// Sets the web settings.
83     void webSettings(WebSettings newWebSettings)
84     {
85       _webSettings = newWebSettings;
86     }
87   }
88 }