Skip to content

Commit

Permalink
use GitHub token
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaoHans committed Nov 3, 2024
1 parent d535612 commit 11b7474
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions samples/CRM.Blazor.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
},
"StringEncryption": {
"DefaultPassPhrase": "78snMkXcCsKr3opA"
},
"GitHub": {
"Token": "github_pat_xxxxxxxx"
}
}
15 changes: 14 additions & 1 deletion samples/CRM.Domain/CRMDomainModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CRM.MultiTenancy;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp;
using Volo.Abp.AuditLogging;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.BlobStoring.Database;
Expand Down Expand Up @@ -40,6 +41,9 @@ public class CRMDomainModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var environment = context.Services.GetAbpHostEnvironment();

Configure<AbpMultiTenancyOptions>(options =>
{
options.IsEnabled = MultiTenancyConsts.IsEnabled;
Expand Down Expand Up @@ -76,7 +80,16 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
httpClient.BaseAddress = new Uri("https://api.github.com");
httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
httpClient.DefaultRequestHeaders.Add("User-Agent", "HttpRequestsSample");
if (environment.IsDevelopment())
{
// 调用github api接口会有频率限制
httpClient.DefaultRequestHeaders.Add("User-Agent", "HttpRequestsSample");
}
else
{
// 生产环境使用自己的GitHub账号生成的Token,可以无限调用github api接口
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {configuration["GitHub:Token"]}");
}
}
);
}
Expand Down

0 comments on commit 11b7474

Please sign in to comment.