Skip to content

Commit

Permalink
Merge branch 'v1.0.0' of https://gitee.com/hejiale010426/FastGateway
Browse files Browse the repository at this point in the history
…into v1.0.0
  • Loading branch information
239573049 committed May 16, 2024
2 parents 9920a45 + d9726ca commit 4bc4d31
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 80 deletions.
4 changes: 2 additions & 2 deletions README-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FastGateway提供了基本的管理服务,提供简单的登录授权,和实时配置管理,从而实现动态路由的管理。

-----
文档语言: [English](README.md) | [简体中文](README.zh-cn.md)
文档语言: [English](README.md) | [简体中文](README-zh-cn.md)

## 支持功能

Expand Down Expand Up @@ -108,7 +108,7 @@ Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-fastgateway
User=www-data
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-fastgateway
User=www-data
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
Expand Down Expand Up @@ -153,4 +153,4 @@ systemctl restart fastgateway.service

## Third-Party Downloads

- [ip2region.xdb](https://tokenfile.oss-cn-beijing.aliyuncs.com/ip2region.xdb) for offline IP attribution
- [ip2region.xdb](https://tokenfile.oss-cn-beijing.aliyuncs.com/ip2region.xdb) for offline IP attribution
61 changes: 19 additions & 42 deletions src/FastGateway/Services/ApiServiceService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Collections.Concurrent;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using AspNetCoreRateLimit;
using AspNetCoreRateLimit;
using FastGateway.Infrastructures;
using FastGateway.Middlewares;
using FastGateway.TunnelServer;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Collections.Concurrent;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using Yarp.ReverseProxy.Configuration;
using Yarp.ReverseProxy.Transforms;
using Directory = System.IO.Directory;
Expand Down Expand Up @@ -360,25 +359,23 @@ private static async Task BuilderService(object state)

builder.WebHost.UseKestrel(options =>
{
options.ConfigureHttpsDefaults(adapterOptions =>
{
if (service.IsHttps)
{
adapterOptions.ServerCertificateSelector = (context, name) =>
CertService.Certs.TryGetValue(name, out var cert)
? new X509Certificate2(cert.File, cert.Password)
: new X509Certificate2(Path.Combine(AppContext.BaseDirectory, "gateway.pfx"), "010426");
}
});
options.Listen(IPAddress.Any, service.Listen);
options.Listen(IPAddress.Parse("0.0.0.0"), service.Listen, listenOptions =>
if (HasHttpService && service.IsHttps)
{
if (!service.IsHttps) return;
listenOptions.UseHttps();
options.Listen(IPAddress.Any, 443, listenOptions =>
{
listenOptions.UseHttps(adapterOptions =>
{
adapterOptions.ServerCertificateSelector = (context, name) =>
CertService.Certs.TryGetValue(name, out var cert)
? new X509Certificate2(cert.File, cert.Password)
: new X509Certificate2(Path.Combine(AppContext.BaseDirectory, "gateway.pfx"), "010426");
});
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
});
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
});
}
options.Limits.MaxRequestBodySize = null;
});
Expand Down Expand Up @@ -461,8 +458,7 @@ private static async Task BuilderService(object state)

var app = builder.Build();


if (service is { RedirectHttps: true, IsHttps: false })
if (service.RedirectHttps)
{
app.UseHttpsRedirection();
}
Expand Down Expand Up @@ -490,25 +486,6 @@ private static async Task BuilderService(object state)
app.UseIpRateLimiting();
}


if (service.RedirectHttps)
{
app.Use(async (context, next) =>
{
if (context.Request.Scheme == "http")
{
var host = context.Request.Host;
var path = context.Request.Path;
var query = context.Request.QueryString;
context.Response.Redirect($"https://{host}{path}{query}");
return;
}
await next(context);
});
}

WebApplications.Add(service.Id, app);

// 如果启用白名单则添加中间件
Expand Down
36 changes: 17 additions & 19 deletions web/src/pages/http-proxy/features/CreateHttpProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,29 @@ export default function CreateHttpProxy({
}}
></Input>
</Col>
<Col span={4}>
<Col span={2}>
<Checkbox
field="isHttps"
onChange={(v: any) => {
values.isHttps = v;
formApi.setValues(values);
}}
label="SSL"
label="启用SSL"
style={{
marginTop: '10px',
marginLeft: '10px',
}}
></Checkbox>
</Col>
<Col span={2}>
<Checkbox
field="redirectHttps"
label="强制跳转HTTPS"
initValue={false}
onChange={(v: any) => {
values.redirectHttps = v;
formApi.setValues(values);
}}
style={{
marginTop: '10px',
marginLeft: '10px',
Expand Down Expand Up @@ -160,23 +175,6 @@ export default function CreateHttpProxy({
></Checkbox>
</Col>
</Row>
<Row>
<Col span={12}>
<Checkbox
field="redirectHttps"
label="启用HTTPS重定向"
initValue={false}
onChange={(v: any) => {
values.redirectHttps = v;
formApi.setValues(values);
}}
style={{
marginTop: '5px',
marginLeft: '10px',
}}
></Checkbox>
</Col>
</Row>
<Row>
<Col span={12}>
<Checkbox
Expand Down
28 changes: 13 additions & 15 deletions web/src/pages/http-proxy/features/UpdateHttpProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function UpdateHttpProxy({

return (
<Modal
title="新建HTTP代理"
title="修改HTTP代理"
visible={visible}
onCancel={onClose}
fullScreen
Expand Down Expand Up @@ -109,34 +109,32 @@ export default function UpdateHttpProxy({
}}
></Input>
</Col>
<Col span={4}>
<Col span={2}>
<Checkbox
field="isHttps"
initValue={values.isHttps}
onChange={(v: any) => {
values.isHttps = v;
formApi.setValues(values);
}}
label="使用HTTPS"
label="启用SSL"
style={{
marginTop: '10px',
marginLeft: '10px',
}}
></Checkbox>
</Col>
</Row>
<Row>
<Col span={12}>
<Col span={2}>
<Checkbox
field="enableFlowMonitoring"
initValue={values.enableFlowMonitoring}
label="启用流量监控"
field="redirectHttps"
label="强制跳转HTTPS"
initValue={values.redirectHttps}
onChange={(v: any) => {
values.enableFlowMonitoring = v;
values.redirectHttps = v;
formApi.setValues(values);
}}
style={{
marginTop: '5px',
marginTop: '10px',
marginLeft: '10px',
}}
></Checkbox>
Expand All @@ -145,11 +143,11 @@ export default function UpdateHttpProxy({
<Row>
<Col span={12}>
<Checkbox
field="redirectHttps"
label="启用HTTPS重定向"
initValue={values.redirectHttps}
field="enableFlowMonitoring"
initValue={values.enableFlowMonitoring}
label="启用流量监控"
onChange={(v: any) => {
values.redirectHttps = v;
values.enableFlowMonitoring = v;
formApi.setValues(values);
}}
style={{
Expand Down

0 comments on commit 4bc4d31

Please sign in to comment.