HttpServerBoxed 0.0.11 alpha
A simple http server for C# and .NET
Loading...
Searching...
No Matches
HSBBootstrapper.Bootstrapper Class Reference

Static Public Member Functions

static void HSBMain (string[] args)
 

Detailed Description

Definition at line 7 of file Bootstrapper.cs.

Member Function Documentation

◆ HSBMain()

static void HSBBootstrapper.Bootstrapper.HSBMain ( string[]  args)
static

Definition at line 26 of file Bootstrapper.cs.

27 {
28 List<string> assemblies = [];
29 List<string> _args = new(args);
30
31 Terminal.Write("====================================================");
32 Terminal.Write("\nHSB-# Standalone Bootstrapper\n");
33
34 Configuration conf = new();
35 string path = "./config.json";
36
37 if (_args.Count != 0)
38 {
39 //print args
40 Terminal.INFO("Arguments passed to the bootstrap:");
41 foreach (string s in _args)
42 {
43 Terminal.INFO("\t" + s);
44 }
45
46 foreach (string s in _args)
47 {
48 if (s.StartsWith("--no-verbose"))
49 {
50 conf.Debug = new Debugger
51 {
52 verbose = false
53 };
54 }
55 if (s.StartsWith("--config-path="))
56 {
57 path = s.Split("--config-path=")[1];
58 }
59 if (s.StartsWith("--create-default"))
60 {
61 Console.WriteLine("Creating default configuration and exiting...");
62
63 conf = new Configuration();
64 conf.AddCustomGlobalHeader("content-encoding", "utf-8");
65
66 var str = JsonSerializer.Serialize(conf, sr);//JsonConvert.SerializeObject(conf);
67 File.WriteAllText(path, str);
68 Terminal.INFO("This is the default configuration : ");
69 Terminal.INFO(str);
70 Terminal.WriteLine("Goodbye\n====================================================");
71 return;
72 }
73 if (s.StartsWith("--assembly="))
74 {
75 assemblies.Add(s.Split("--assembly=")[1]);
76 }
77 if (s.StartsWith("--port="))
78 {
79 conf.Port = ushort.Parse(s.Split("--port=")[1]);
80 }
81 if (s.StartsWith("--address="))
82 {
83 conf.Address = s.Split("--address=")[1];
84 }
85 if (s.StartsWith("--info") || s.StartsWith('?'))
86 {
87 Utils.PrintLogo();
88 Terminal.WriteLine("Available commands :");
89 Terminal.WriteLine("--config-path : \tSpecifies a path for the json configuration of the server");
90 Terminal.WriteLine("--create-default : \tCreates a default configuration");
91 Terminal.WriteLine("--info, ? : \tShow this message screen");
92 Terminal.WriteLine("--no-verbose : \tDisables verbose writing");
93 Terminal.WriteLine("--port : \t Set server listening port");
94 Terminal.WriteLine("--address : \t Set server listening address");
95 Terminal.WriteLine("--assembly : \tUse it to load custom assemblies (use it to run without embedding HSB");
96 return;
97 }
98
99 }
100 }
101 if (assemblies.Count > 0)
102 {
103 Terminal.INFO("Loading following assemblies:");
104 foreach (var a in assemblies)
105 {
106 Terminal.INFO("\t" + a);
107 if (a != "")
108 Assembly.LoadFile(Path.GetFullPath(a));
109 }
110 }
111
112 // Utils.printLoadedAssemblies();
113
114 if (File.Exists(path))
115 {
116 using StreamReader r = new(path);
117 string json = r.ReadToEnd();
118
119 try
120 {
121 conf = new Configuration(json);
122 }
123 catch (Exception e)
124 {
125
126 Terminal.ERROR("Invalid configuration file");
127 Terminal.ERROR(e);
128 return;
129 }
130
131 if (conf.Debug.verbose)
132 {
133 Terminal.INFO("Configuration file loaded successfully, preview:");
134 Terminal.INFO(json);
135 }
136 }
137 else
138 {
139 Terminal.WARNING("Configuration file not found");
140 Terminal.WriteLine("Insert one or create one with the following commands:");
141 Terminal.WriteLine("Usage :");
142 Terminal.WriteLine("\t--config-path : \tSpecifies a path for the json configuration of the server");
143 Terminal.WriteLine("\t--create-default : \tCreates a default configuration");
144 Terminal.WriteLine("\t--info : \tShow this message screen");
145 Terminal.WriteLine("\t--no-verbose : \tDisables verbose writing");
146 Terminal.WriteLine("\t--port : \t Set server listening port");
147 Terminal.WriteLine("\t--address : \t Set server listening address");
148 Terminal.WriteLine("\t--assembly : \tUse it to load custom assemblies (use it to run without embedding HSB");
149 Terminal.WriteLine("HSB-# will start with default failsafe configuration\n\n");
150 //conf = new Configuration();
151 }
152
153 if (conf == null)
154 {
155 Terminal.ERROR("Something happened building the server configuration, exiting...");
156 return;
157 }
158 else
159 {
160 Terminal.INFO("The bootstrap has finished, HSB will start now");
161 Terminal.Write("====================================================\n");
162 }
163
164 try
165 {
166 new Server(conf).Start();
167 }
168 catch (Exception e)
169 {
170 Terminal.ERROR("Error starting server ->");
171 Terminal.ERROR(e.Message);
172 Terminal.ERROR("The server has crashed! Exiting...");
173 return;
174 }
175
176 }
This class contains all the settings of the server.
void AddCustomGlobalHeader(string name, string value)
Add an HTTP Response header that will be added to ALL the responses.
Debugger Debug
Holds all debug information and routines.

The documentation for this class was generated from the following file: