2022-01-02 00:23:39 +08:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
|
// You may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
|
|
|
// Copyright (c) 2019 Gui.H
|
|
|
|
|
2022-12-03 21:29:17 +08:00
|
|
|
using System.Net.Http;
|
|
|
|
using System.Net.Sockets;
|
2022-12-03 22:26:17 +08:00
|
|
|
using FastTunnel.Core.Extensions;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2020-08-18 09:33:08 +08:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2021-04-27 14:29:34 +08:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-12-03 22:26:17 +08:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-11-01 00:07:31 +08:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-06-23 16:19:27 +08:00
|
|
|
using Serilog;
|
2022-12-03 21:29:17 +08:00
|
|
|
using Serilog.Events;
|
2019-12-16 10:29:06 +08:00
|
|
|
|
2022-01-02 00:23:39 +08:00
|
|
|
namespace FastTunnel.Server;
|
|
|
|
|
|
|
|
public class Program
|
2019-12-16 10:29:06 +08:00
|
|
|
{
|
2022-01-02 00:23:39 +08:00
|
|
|
public static void Main(string[] args)
|
2019-12-16 10:29:06 +08:00
|
|
|
{
|
2022-12-03 21:29:17 +08:00
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
|
|
.Enrich.FromLogContext()
|
|
|
|
.WriteTo.Console().WriteTo.File("Logs/log-.log", rollingInterval: RollingInterval.Day)
|
|
|
|
.CreateBootstrapLogger();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2022-12-03 22:26:17 +08:00
|
|
|
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
|
|
|
{
|
|
|
|
Args = args
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
|
|
builder.Host.UseSerilog((context, services, configuration) => configuration
|
|
|
|
.ReadFrom.Configuration(context.Configuration)
|
|
|
|
.ReadFrom.Services(services)
|
|
|
|
.Enrich.FromLogContext()
|
|
|
|
.WriteTo.Console());
|
|
|
|
|
|
|
|
(builder.Configuration as IConfigurationBuilder).AddJsonFile("config/appsettings.json", optional: false, reloadOnChange: true);
|
|
|
|
(builder.Configuration as IConfigurationBuilder).AddJsonFile($"config/appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true); ;
|
|
|
|
|
|
|
|
// -------------------FastTunnel STEP1 OF 3------------------
|
|
|
|
builder.Services.AddFastTunnelServer(builder.Configuration.GetSection("FastTunnel"));
|
|
|
|
// -------------------FastTunnel STEP1 END-------------------
|
|
|
|
|
|
|
|
builder.Host.UseWindowsService();
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
2022-12-03 21:29:17 +08:00
|
|
|
|
2022-12-03 22:26:17 +08:00
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
// -------------------FastTunnel STEP2 OF 3------------------
|
|
|
|
app.UseFastTunnelServer();
|
|
|
|
// -------------------FastTunnel STEP2 END-------------------
|
|
|
|
|
|
|
|
app.MapFastTunnelServer();
|
|
|
|
|
|
|
|
app.Run();
|
2022-12-03 21:29:17 +08:00
|
|
|
}
|
|
|
|
catch (System.Exception ex)
|
|
|
|
{
|
|
|
|
Log.Fatal(ex, "致命异常");
|
|
|
|
throw;
|
|
|
|
}
|
2022-01-02 00:23:39 +08:00
|
|
|
}
|
2019-12-16 10:29:06 +08:00
|
|
|
}
|