SetDefaultRoute() public method

public SetDefaultRoute ( Func Route ) : void
Route Func
return void
Ejemplo n.º 1
0
		static public void Main(string[] args)
		{
			Core.Loop(async () =>
			{
				var Server = new HttpServer();
				var Router = new HttpRouter();

				Router.AddRoute("/test", async (Request, Response) =>
				{
					Response.Buffering = true;

					Response.SetHttpCode(HttpCode.OK_200);
					Response.Headers["Content-Type"] = "application/json";

					var MysqlClient = new MysqlClient("FEDORADEV", User: "******", Password: "******");
					await MysqlClient.ConnectAsync();

					foreach (var Row in await MysqlClient.QueryAsync("SELECT 1 as 'k1', 2 as 'k2', 3 * 999, 'test', 1 as 'Ok';"))
					{
						await Response.WriteAsync(Row.ToString());
					}

					await MysqlClient.CloseAsync();
				});

				// Default file serving

				Router.SetDefaultRoute(new HttpStaticFileServer(new LocalFileSystem(@"C:\projects\csharp\NodeNet\static"), Cache: true));

				Server.AddFilterLast(Router);
				await Server.ListenAsync(80, "127.0.0.1");
			});
		}
Ejemplo n.º 2
0
		static public void Main(string[] Args)
		{
			Core.Loop(async () =>
			{
				var Server = new HttpServer();
				var Router = new HttpRouter();

				Router.AddRoute("/test", async (Request, Response) =>
				{
					await Response.WriteAsync("Test!");
				});

				// Default file serving
				Router.SetDefaultRoute(new HttpStaticFileServer(Path: @"C:\projects\csharp\nodenet\NodeNet\static", Cache: true));

				Server.AddFilterLast(Router);
				await Server.ListenAsync(80, "127.0.0.1");
			});
		}