update:docker compose 更新
queries构造函数修改 配置json更新
This commit is contained in:
@@ -4,5 +4,9 @@ services:
|
|||||||
qrcodeservice:
|
qrcodeservice:
|
||||||
environment:
|
environment:
|
||||||
- ASPNETCORE_ENVIRONMENT=Development
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
|
- ConnectionStrings__Default=server=mariadb;user=root;password=root;database=qrcode
|
||||||
ports:
|
ports:
|
||||||
- "80"
|
- 5001:80
|
||||||
|
mariadb:
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=root
|
||||||
@@ -5,4 +5,7 @@ services:
|
|||||||
image: ${DOCKER_REGISTRY-}qrcodeservice
|
image: ${DOCKER_REGISTRY-}qrcodeservice
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: QRCodeService/Dockerfile
|
dockerfile: ../QRCodeService/Dockerfile
|
||||||
|
mariadb:
|
||||||
|
image: mariadb:10.5.9
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ namespace QRCodeService.Application.Queries
|
|||||||
{
|
{
|
||||||
readonly string _connectionString;
|
readonly string _connectionString;
|
||||||
|
|
||||||
public AppQueries(IConfiguration configuration)
|
public AppQueries(string connectionString)
|
||||||
{
|
{
|
||||||
_connectionString = configuration.GetConnectionString("default");
|
_connectionString = connectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<App> GetAppAsync(int id)
|
public async Task<App> GetAppAsync(int id)
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ namespace QRCodeService.Application.Queries
|
|||||||
{
|
{
|
||||||
readonly string _connectionString;
|
readonly string _connectionString;
|
||||||
|
|
||||||
public LinkQueries(IConfiguration configuration)
|
public LinkQueries(string connectionString)
|
||||||
{
|
{
|
||||||
_connectionString = configuration.GetConnectionString("default");
|
_connectionString = connectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Link> GetLinkAsync(string shortCode)
|
public async Task<Link> GetLinkAsync(string shortCode)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using QRCoder;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using QRCodeService.Application.Queries;
|
using QRCodeService.Application.Queries;
|
||||||
using QRCodeService.Models;
|
using QRCodeService.Models;
|
||||||
|
using QRCodeService.Options;
|
||||||
|
|
||||||
namespace QRCodeService.Controllers
|
namespace QRCodeService.Controllers
|
||||||
{
|
{
|
||||||
@@ -17,11 +18,12 @@ namespace QRCodeService.Controllers
|
|||||||
{
|
{
|
||||||
readonly ILinkQueries linkQueries;
|
readonly ILinkQueries linkQueries;
|
||||||
readonly IAppQueries appQueries;
|
readonly IAppQueries appQueries;
|
||||||
|
readonly ServiceOption option;
|
||||||
public ImageController(ILinkQueries linkQueries, IAppQueries appQueries)
|
public ImageController(ILinkQueries linkQueries, IAppQueries appQueries,ServiceOption option)
|
||||||
{
|
{
|
||||||
this.linkQueries = linkQueries;
|
this.linkQueries = linkQueries;
|
||||||
this.appQueries = appQueries;
|
this.appQueries = appQueries;
|
||||||
|
this.option = option;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("qrcode")]
|
[Route("qrcode")]
|
||||||
@@ -43,7 +45,7 @@ namespace QRCodeService.Controllers
|
|||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
var qrCodeGenerator = new QRCodeGenerator();
|
var qrCodeGenerator = new QRCodeGenerator();
|
||||||
var data = qrCodeGenerator.CreateQrCode($"http://localhost:5000/{link.ShortCode}", QRCodeGenerator.ECCLevel.Q);
|
var data = qrCodeGenerator.CreateQrCode($"{option.BaseUrl}r/{link.ShortCode}", QRCodeGenerator.ECCLevel.Q);
|
||||||
var qrCode = new QRCode(data);
|
var qrCode = new QRCode(data);
|
||||||
using (var stream = new MemoryStream())
|
using (var stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace QRCodeService.Controllers
|
namespace QRCodeService.Controllers
|
||||||
{
|
{
|
||||||
[Route("{shortCode}")]
|
[Route("r/{shortCode}")]
|
||||||
public class RedirectController:Controller
|
public class RedirectController:Controller
|
||||||
{
|
{
|
||||||
private readonly ILinkQueries queries;
|
private readonly ILinkQueries queries;
|
||||||
|
|||||||
20
QRCodeService/Options/ServiceOption.cs
Normal file
20
QRCodeService/Options/ServiceOption.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace QRCodeService.Options
|
||||||
|
{
|
||||||
|
public class ServiceOption
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 二维码输出地址的基本路径
|
||||||
|
/// </summary>
|
||||||
|
public string BaseUrl { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 是否布置了反向代理
|
||||||
|
/// </summary>
|
||||||
|
public bool IsForwarded { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ using QRCodeService.Application.Behaviors;
|
|||||||
using QRCodeService.Application.Commands;
|
using QRCodeService.Application.Commands;
|
||||||
using QRCodeService.Application.Queries;
|
using QRCodeService.Application.Queries;
|
||||||
using QRCodeService.Application.Validations;
|
using QRCodeService.Application.Validations;
|
||||||
|
using QRCodeService.Options;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -48,6 +49,9 @@ namespace QRCodeService
|
|||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "QRCodeService", Version = "v1" });
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "QRCodeService", Version = "v1" });
|
||||||
});
|
});
|
||||||
|
//配置
|
||||||
|
services.Configure<ServiceOption>(Configuration.GetSection("hosting"));
|
||||||
|
|
||||||
//validator
|
//validator
|
||||||
services.AddTransient<IValidator<CreateLinkCommand>, CreateLinkCommandValidator>();
|
services.AddTransient<IValidator<CreateLinkCommand>, CreateLinkCommandValidator>();
|
||||||
|
|
||||||
@@ -60,7 +64,7 @@ namespace QRCodeService
|
|||||||
services.AddDbContext<AppDbContext>(
|
services.AddDbContext<AppDbContext>(
|
||||||
dbContextOptions => dbContextOptions
|
dbContextOptions => dbContextOptions
|
||||||
.UseMySql(
|
.UseMySql(
|
||||||
"server=localhost;user=root;password=root;database=qrcode",
|
Configuration.GetConnectionString("Default"),
|
||||||
// For common usages, see pull request #1233.
|
// For common usages, see pull request #1233.
|
||||||
new MariaDbServerVersion(new Version(10, 5, 9)), // use MariaDbServerVersion for MariaDB
|
new MariaDbServerVersion(new Version(10, 5, 9)), // use MariaDbServerVersion for MariaDB
|
||||||
mySqlOptions => mySqlOptions
|
mySqlOptions => mySqlOptions
|
||||||
@@ -74,8 +78,8 @@ namespace QRCodeService
|
|||||||
services.AddScoped<IAppRepository, AppRepository>();
|
services.AddScoped<IAppRepository, AppRepository>();
|
||||||
services.AddScoped<ILinkRepository, LinkRepository>();
|
services.AddScoped<ILinkRepository, LinkRepository>();
|
||||||
//Queries
|
//Queries
|
||||||
services.AddScoped<ILinkQueries, LinkQueries>();
|
services.AddScoped<ILinkQueries, LinkQueries>( s=>new LinkQueries(Configuration.GetConnectionString("Default")));
|
||||||
services.AddScoped<IAppQueries, AppQueries>();
|
services.AddScoped<IAppQueries, AppQueries>(s => new AppQueries(Configuration.GetConnectionString("Default")));
|
||||||
//redis cache
|
//redis cache
|
||||||
services.AddDistributedRedisCache(options=>options.Configuration=Configuration.GetSection("redis:default").Value);
|
services.AddDistributedRedisCache(options=>options.Configuration=Configuration.GetSection("redis:default").Value);
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ namespace QRCodeService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ServiceOption option)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
@@ -96,7 +100,10 @@ namespace QRCodeService
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QRCodeService v1"));
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QRCodeService v1"));
|
||||||
}
|
}
|
||||||
app.UseForwardedHeaders();
|
if (option.IsForwarded)
|
||||||
|
{
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Debug",
|
||||||
"Microsoft": "Warning",
|
"Microsoft": "Warning",
|
||||||
"Microsoft.Hosting.Lifetime": "Information"
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
}
|
}
|
||||||
|
|||||||
6
QRCodeService/appsettings.Production.json
Normal file
6
QRCodeService/appsettings.Production.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Hosting": {
|
||||||
|
"BaseUrl": "http://qrcode.bobandjuly.cyou/",
|
||||||
|
"IsForwarded": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"default": "server=localhost;user=root;password=root;database=qrcode"
|
"Default": "server=localhost;user=root;password=root;database=qrcode"
|
||||||
},
|
},
|
||||||
"Serilog": {
|
"Serilog": {
|
||||||
"Using": [ "SeriLog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async" ],
|
"Using": [ "SeriLog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async" ],
|
||||||
@@ -49,5 +49,9 @@
|
|||||||
"InstanceName": "local",
|
"InstanceName": "local",
|
||||||
"DefaultDB": 8
|
"DefaultDB": 8
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Hosting": {
|
||||||
|
"BaseUrl": "http://localhost:5000/",
|
||||||
|
"IsForwarded": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user