示例#1
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Debug.WriteLine("Provide path or file that contains the JSON configuration. If file does not exit then default one will be created.");
                return;
            }

            if (!File.Exists(args[0]))
            {
                ProgramConfig defcfg = new ProgramConfig
                {
                    auth_url           = "(required) The HTTP or HTTPS URL to the authentication service.",
                    db_url             = "(required) The HTTP or HTTPS URL to the database service.",
                    port               = 80,
                    web_resources_path = "(required) The path to the web resources to serve.",
                };

                var defcfgfp = File.CreateText(args[1]);
                defcfgfp.Write(JsonConvert.SerializeObject(defcfg, Formatting.Indented));
                defcfgfp.Dispose();

                Debug.WriteLine("Default configuration created at location specified.");
                return;
            }

            var cfgfp = File.OpenText(args[0]);

            var cfg = JsonConvert.DeserializeObject <ProgramConfig>(cfgfp.ReadToEnd());

            cfgfp.Dispose();

            var server_state = new ServerCore(cfg);

            var handlers = new Dictionary <String, SimpleServer <ServerCore> .SimpleHTTPHandler>();

            handlers.Add("/", Handlers.Index);
            handlers.Add("/utility", Handlers.Utility);
            handlers.Add("/get-config", Handlers.GetConfig);

            var server_task = SimpleServer <ServerCore> .Create(
                server_state,
                handlers,
                cfg.port,
                cfg.ssl_cert_path,
                cfg.ssl_cert_pass
                );

            server_task.Wait();
        }
示例#2
0
        public static async Task <Task> GetConfig(ServerCore core, HTTPRequest request, Stream body, IProxyHTTPEncoder encoder)
        {
            await MDACS.Server.Util.ReadStreamUntilEndAndDiscardDataAsync(body);

            var resp = new JObject();

            resp["dbUrl"]   = core.GetDatabaseUrl();
            resp["authUrl"] = core.GetAuthUrl();

            await encoder.WriteQuickHeader(200, "OK");

            await encoder.BodyWriteSingleChunk(JsonConvert.SerializeObject(resp));

            return(Task.CompletedTask);
        }
示例#3
0
 public static async Task <Task> Utility(ServerCore core, HTTPRequest request, Stream body, IProxyHTTPEncoder encoder)
 {
     return(await core.ServeData(request.query_string, encoder));
 }
示例#4
0
 public static async Task <Task> Index(ServerCore core, HTTPRequest request, Stream body, IProxyHTTPEncoder encoder)
 {
     return(await core.ServeData("index.html", encoder));
 }