static void Main(string[] args) { TwinoMvc mvc = new TwinoMvc(); TwinoServer server = new TwinoServer(); mvc.Init(); server.UseMvc(mvc, HttpOptions.CreateDefault()); server.Start(); server.BlockWhileRunning(); }
static void Main(string[] args) { TwinoMvc mvc = new TwinoMvc(); TwinoServer server = new TwinoServer(); mvc.Init(); server.UseMvc(mvc); server.Start(5000); server.BlockWhileRunning(); }
static void Main(string[] args) { TwinoServer _server = new TwinoServer(); _server = new TwinoServer(ServerOptions.CreateDefault()); _server.UseWebSockets(async(socket) => { await socket.SendAsync("Welcome"); }, async(socket, message) => { Console.WriteLine("# " + message); await socket.SendAsync(message); }); _server.Start(46100); _server.BlockWhileRunning(); }
static void Main(string[] args) { using TwinoMvc mvc = new TwinoMvc(); mvc.IsDevelopment = false; mvc.Init(twino => { twino.Services.AddScoped <IScopedService, ScopedService>(); twino.Services.AddTransient <IFirstService, FirstService>(); twino.Services.AddTransient <ISecondService, SecondService>(); twino.AddJwt(options => { options.Key = "Very_very_secret_key"; options.Issuer = "localhost"; options.Audience = "localhost"; options.Lifetime = TimeSpan.FromHours(1); options.ValidateAudience = false; options.ValidateIssuer = false; options.ValidateLifetime = true; }); twino.Policies.Add(Policy.RequireRole("Admin", "Admin")); twino.Policies.Add(Policy.RequireClaims("IT", "Database", "Cloud", "Source")); twino.Policies.Add(Policy.Custom("Custom", (d, c) => true)); twino.Services.AddHttpClient(); twino.StatusCodeResults.Add(HttpStatusCode.Unauthorized, new JsonResult(new { Message = "Access denied" })); }); CorsMiddleware cors = new CorsMiddleware(); cors.AllowAll(); mvc.Use(app => { app.UseMiddleware(cors); app.UseMiddleware <TMid>(); app.UseFiles("/download", "/home/mehmet/files"); }); TwinoServer server = new TwinoServer(); var opt = HttpOptions.CreateDefault(); opt.HttpConnectionTimeMax = 0; server.UseMvc(mvc, opt); server.Start(441); server.BlockWhileRunning(); }
static void Main(string[] args) { TwinoServer server = new TwinoServer(ServerOptions.CreateDefault()); server.UseHttp(async(request, response) => { if (request.Path.Equals("/plaintext", StringComparison.InvariantCultureIgnoreCase)) { response.SetToText(); await response.WriteAsync("Hello, World!"); } else { response.StatusCode = HttpStatusCode.NotFound; } }); server.Start(82); server.BlockWhileRunning(); }
static void Main(string[] args) { TwinoServer server = new TwinoServer(ServerOptions.CreateDefault()); server.UseHttp(async(request, response) => { if (request.Path.Equals("/json", StringComparison.InvariantCultureIgnoreCase)) { response.SetToJson(new { message = "Hello, World!" }); } else { response.StatusCode = HttpStatusCode.NotFound; } await Task.CompletedTask; }, HttpOptions.CreateDefault()); server.Start(); server.BlockWhileRunning(); }