mirror of
https://github.com/ryzij/URL-Shortener.git
synced 2026-07-14 03:56:58 +00:00
Compare commits
10 Commits
474bc561a5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a9746b8d0d | |||
| 067a1a6055 | |||
| da47d7fdf3 | |||
| d659a0289f | |||
| 4a4ee24ce7 | |||
| e55c54e75d | |||
| 99973eba04 | |||
| 4dec3251a0 | |||
| 15917d7c7e | |||
| 5aa135cd0c |
@@ -1,3 +1,6 @@
|
|||||||
POSTGRES_USER=app
|
POSTGRES_USER=app
|
||||||
POSTGRES_PASSWORD=app
|
POSTGRES_PASSWORD=app
|
||||||
POSTGRES_DB=appdb
|
POSTGRES_DB=appdb
|
||||||
|
|
||||||
|
JWT_SECRET_KEY=mysecretkeyqwertyuiopasdfghjklzxcvbnm
|
||||||
|
JWT_EXPIRES=00:01:00
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
# См. статью по ссылке https://aka.ms/customizecontainer, чтобы узнать как настроить контейнер отладки и как Visual Studio использует этот Dockerfile для создания образов для ускорения отладки.
|
|
||||||
|
|
||||||
# Этот этап используется при запуске из VS в быстром режиме (по умолчанию для конфигурации отладки)
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
|
|
||||||
USER $APP_UID
|
|
||||||
WORKDIR /app
|
|
||||||
EXPOSE 8080
|
|
||||||
EXPOSE 8081
|
|
||||||
|
|
||||||
# Этот этап используется для сборки проекта службы
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
|
||||||
WORKDIR /src
|
|
||||||
COPY ["URL-Shortener/URL-Shortener.csproj", "URL-Shortener/"]
|
|
||||||
RUN dotnet restore "./URL-Shortener/URL-Shortener.csproj"
|
|
||||||
COPY . .
|
|
||||||
WORKDIR "/src/URL-Shortener"
|
|
||||||
RUN dotnet build "./URL-Shortener.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
|
||||||
|
|
||||||
# Этот этап используется для публикации проекта службы, который будет скопирован на последний этап
|
|
||||||
FROM build AS publish
|
|
||||||
ARG BUILD_CONFIGURATION=Release
|
|
||||||
RUN dotnet publish "./URL-Shortener.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
|
||||||
|
|
||||||
# Этот этап используется в рабочей среде или при запуске из VS в обычном режиме (по умолчанию, когда конфигурация отладки не используется)
|
|
||||||
FROM base AS final
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=publish /app/publish .
|
|
||||||
ENTRYPOINT ["dotnet", "URL-Shortener.dll"]
|
|
||||||
@@ -31,6 +31,9 @@ cp .env.example .env
|
|||||||
POSTGRES_USER=app
|
POSTGRES_USER=app
|
||||||
POSTGRES_PASSWORD=app
|
POSTGRES_PASSWORD=app
|
||||||
POSTGRES_DB=appdb
|
POSTGRES_DB=appdb
|
||||||
|
|
||||||
|
JWT_SECRET_KEY=mysecretkeyqwertyuiopasdfghjklzxcvbnm
|
||||||
|
JWT_EXPIRES=00:01:00
|
||||||
```
|
```
|
||||||
|
|
||||||
### Настройка `docker-compose.yml`
|
### Настройка `docker-compose.yml`
|
||||||
@@ -43,13 +46,17 @@ cp docker-compose.example.yml docker-compose.yml
|
|||||||
```yml
|
```yml
|
||||||
services:
|
services:
|
||||||
api:
|
api:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: URL-Shortener/Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "5000:8080"
|
- "5000:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
environment:
|
environment:
|
||||||
ConnectionStrings__DefaultConnection: Host=db;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}
|
ConnectionStrings__DefaultConnection: Host=db;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}
|
||||||
|
AuthSettings__SecretKey: ${JWT_SECRET_KEY}
|
||||||
|
AuthSettings__Expires: "${JWT_EXPIRES}"
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:17
|
image: postgres:17
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using URL_Shortener.DTO;
|
using URL_Shortener.DTO;
|
||||||
using URL_Shortener.Models;
|
using URL_Shortener.Models;
|
||||||
using HashidsNet;
|
using HashidsNet;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using URL_Shortener.Extensions;
|
||||||
|
|
||||||
namespace URL_Shortener.Controllers
|
namespace URL_Shortener.Controllers
|
||||||
{
|
{
|
||||||
@@ -38,13 +41,15 @@ namespace URL_Shortener.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[Authorize]
|
||||||
public async Task<IActionResult> CreateShortUrlAsync(CreateShortUrlDto dto)
|
public async Task<IActionResult> CreateShortUrlAsync(CreateShortUrlDto dto)
|
||||||
{
|
{
|
||||||
var shortUrl = new ShortUrl
|
var shortUrl = new ShortUrl
|
||||||
{
|
{
|
||||||
OriginalUrl = dto.OriginalUrl,
|
OriginalUrl = dto.OriginalUrl,
|
||||||
ExpirationDateTime = dto.ExpirationDateTime,
|
ExpirationDateTime = dto.ExpirationDateTime,
|
||||||
ClickLimit = dto.ClickLimit
|
ClickLimit = dto.ClickLimit,
|
||||||
|
UserId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!)
|
||||||
};
|
};
|
||||||
await _db.ShortUrls.AddAsync(shortUrl);
|
await _db.ShortUrls.AddAsync(shortUrl);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
@@ -55,12 +60,16 @@ namespace URL_Shortener.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPatch("{id:int}")]
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize]
|
||||||
public async Task<IActionResult> UpdateShortUrlAsync(int id, UpdateShortUrlDto dto)
|
public async Task<IActionResult> UpdateShortUrlAsync(int id, UpdateShortUrlDto dto)
|
||||||
{
|
{
|
||||||
var shortUrl = await _db.ShortUrls.FindAsync(id);
|
var shortUrl = await _db.ShortUrls.FindAsync(id);
|
||||||
if (shortUrl == null)
|
if (shortUrl == null)
|
||||||
return NotFound("Short URL not found");
|
return NotFound("Short URL not found");
|
||||||
|
|
||||||
|
if (!User.CompareId(shortUrl.UserId))
|
||||||
|
throw new Exception("Not authorized");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(dto.OriginalUrl))
|
if (!string.IsNullOrEmpty(dto.OriginalUrl))
|
||||||
shortUrl.OriginalUrl = dto.OriginalUrl;
|
shortUrl.OriginalUrl = dto.OriginalUrl;
|
||||||
if (dto.ExpirationDateTime.HasValue)
|
if (dto.ExpirationDateTime.HasValue)
|
||||||
@@ -78,12 +87,16 @@ namespace URL_Shortener.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("{id:int}")]
|
[HttpDelete("{id:int}")]
|
||||||
|
[Authorize]
|
||||||
public async Task<IActionResult> DeleteShortUrlByIdAsync(int id)
|
public async Task<IActionResult> DeleteShortUrlByIdAsync(int id)
|
||||||
{
|
{
|
||||||
var shortUrl = await _db.ShortUrls.FindAsync(id);
|
var shortUrl = await _db.ShortUrls.FindAsync(id);
|
||||||
if (shortUrl == null)
|
if (shortUrl == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
if (!User.CompareId(shortUrl.UserId))
|
||||||
|
throw new Exception("Not authorized");
|
||||||
|
|
||||||
_db.ShortUrls.Remove(shortUrl);
|
_db.ShortUrls.Remove(shortUrl);
|
||||||
|
|
||||||
var clickInfos = _db.ClickInfos.Where(c => c.ShortUrlId == id);
|
var clickInfos = _db.ClickInfos.Where(c => c.ShortUrlId == id);
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using URL_Shortener.Models;
|
|
||||||
using URL_Shortener.DTO;
|
using URL_Shortener.DTO;
|
||||||
|
using URL_Shortener.Services;
|
||||||
|
|
||||||
namespace URL_Shortener.Controllers
|
namespace URL_Shortener.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("user")]
|
[Route("user")]
|
||||||
public class UserController(AppDbContext db) : ControllerBase
|
public class UserController(UserService userService) : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _db = db;
|
private readonly UserService _userService = userService;
|
||||||
|
|
||||||
[HttpGet("email")]
|
[HttpPost("register")]
|
||||||
public async Task<IActionResult> GetUserByEmailAsync(string email)
|
public async Task<IActionResult> RegisterAsync(RegisterUserDTO dto)
|
||||||
{
|
{
|
||||||
var user = await _db.Users.FirstOrDefaultAsync(u => u.Email == email);
|
var jwt = await _userService.RegisterAsync(dto.Name, dto.Email, dto.Password);
|
||||||
if (user == null)
|
return Ok(jwt);
|
||||||
return NotFound("User not found");
|
}
|
||||||
|
|
||||||
return Ok(user);
|
[HttpPost("login")]
|
||||||
|
public async Task<IActionResult> LoginAsync(LoginUserDTO dto)
|
||||||
|
{
|
||||||
|
var jwt = await _userService.LoginAsync(dto.Email, dto.Password);
|
||||||
|
return Ok(jwt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace URL_Shortener.DTO
|
||||||
|
{
|
||||||
|
public class LoginUserDTO
|
||||||
|
{
|
||||||
|
[Required, EmailAddress]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace URL_Shortener.DTO
|
||||||
|
{
|
||||||
|
public class RegisterUserDTO
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[Required, EmailAddress]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
namespace URL_Shortener.Extensions;
|
||||||
|
|
||||||
|
public static class ClaimsPrincipalExtensions
|
||||||
|
{
|
||||||
|
public static bool CompareId(this ClaimsPrincipal claimsPrincipal, int userId)
|
||||||
|
{
|
||||||
|
return int.TryParse(claimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier), out int id) &&
|
||||||
|
id == userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using URL_Shortener;
|
using URL_Shortener;
|
||||||
|
using URL_Shortener.Services;
|
||||||
|
using URL_Shortener.Settings;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Microsoft.OpenApi;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -10,11 +16,41 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddOpenApi();
|
builder.Services.AddOpenApi();
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.AddSecurityDefinition("bearer", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Type = SecuritySchemeType.Http,
|
||||||
|
Scheme = "bearer",
|
||||||
|
BearerFormat = "JWT",
|
||||||
|
Description = "JWT Authorization header using the Bearer scheme."
|
||||||
|
});
|
||||||
|
|
||||||
|
options.AddSecurityRequirement(document => new OpenApiSecurityRequirement
|
||||||
|
{
|
||||||
|
[new OpenApiSecuritySchemeReference("bearer", document)] = []
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Чтобы короткие коды генерировать
|
|
||||||
builder.Services.AddSingleton<HashidsNet.Hashids>();
|
builder.Services.AddSingleton<HashidsNet.Hashids>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<UserService>();
|
||||||
|
builder.Services.AddScoped<JwtService>();
|
||||||
|
|
||||||
|
var authSettings = builder.Configuration.GetSection("AuthSettings");
|
||||||
|
builder.Services.Configure<AuthSettings>(authSettings);
|
||||||
|
|
||||||
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(o => o.TokenValidationParameters = new()
|
||||||
|
{
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidateAudience = false,
|
||||||
|
ValidateIssuer = false,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(
|
||||||
|
authSettings.Get<AuthSettings>()!.SecretKey))
|
||||||
|
});
|
||||||
|
|
||||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||||
{
|
{
|
||||||
var connString = builder.Configuration.GetConnectionString("DefaultConnection");
|
var connString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
@@ -40,8 +76,7 @@ using (var scope = app.Services.CreateScope())
|
|||||||
retry.Execute(db.Database.Migrate);
|
retry.Execute(db.Database.Migrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
//app.UseHttpsRedirection();
|
app.UseAuthentication();
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using URL_Shortener.Models;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using URL_Shortener.Settings;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
|
namespace URL_Shortener.Services
|
||||||
|
{
|
||||||
|
public class JwtService(IOptions<AuthSettings> options)
|
||||||
|
{
|
||||||
|
public string GenerateToken(User user)
|
||||||
|
{
|
||||||
|
var claims = new List<Claim>() {
|
||||||
|
new(ClaimTypes.Name, user.Name),
|
||||||
|
new(ClaimTypes.Email, user.Email),
|
||||||
|
new(ClaimTypes.NameIdentifier, user.Id.ToString())
|
||||||
|
};
|
||||||
|
var jwt = new JwtSecurityToken(
|
||||||
|
expires: DateTime.UtcNow.Add(options.Value.Expires),
|
||||||
|
claims: claims,
|
||||||
|
signingCredentials: new SigningCredentials(
|
||||||
|
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(options.Value.SecretKey)),
|
||||||
|
SecurityAlgorithms.HmacSha256)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new JwtSecurityTokenHandler().WriteToken(jwt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,42 @@
|
|||||||
namespace URL_Shortener.Services
|
using URL_Shortener.Models;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace URL_Shortener.Services
|
||||||
{
|
{
|
||||||
public class UserService
|
public class UserService(AppDbContext db, JwtService jwtService)
|
||||||
{
|
{
|
||||||
public async Task Register(string userName, string email, string hashedPassword)
|
private readonly AppDbContext _db = db;
|
||||||
|
private readonly JwtService _jwtService = jwtService;
|
||||||
|
|
||||||
|
public async Task<string> RegisterAsync(string userName, string email, string password, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (await _db.Users.FirstOrDefaultAsync(u => u.Email == email, cancellationToken) != null)
|
||||||
|
throw new Exception("This user already exists.");
|
||||||
|
|
||||||
|
var user = new User()
|
||||||
|
{
|
||||||
|
Name = userName,
|
||||||
|
Email = email
|
||||||
|
};
|
||||||
|
user.HashedPassword = new PasswordHasher<User>().HashPassword(user, password);
|
||||||
|
|
||||||
|
await _db.Users.AddAsync(user, cancellationToken);
|
||||||
|
await _db.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return _jwtService.GenerateToken(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> LoginAsync(string email, string password, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var user = await _db.Users.FirstOrDefaultAsync(u => u.Email == email, cancellationToken) ??
|
||||||
|
throw new Exception("User not found.");
|
||||||
|
|
||||||
|
var res = new PasswordHasher<User>().VerifyHashedPassword(user, user.HashedPassword, password);
|
||||||
|
if (res == PasswordVerificationResult.Failed)
|
||||||
|
throw new Exception("Incorrect password.");
|
||||||
|
|
||||||
|
return _jwtService.GenerateToken(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace URL_Shortener.Settings
|
||||||
|
{
|
||||||
|
public class AuthSettings
|
||||||
|
{
|
||||||
|
public string SecretKey { get; set; } = string.Empty;
|
||||||
|
public TimeSpan Expires { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,19 +11,21 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
<PackageReference Include="Hashids.net" Version="1.7.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.7">
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.9">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.7">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.9">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.2" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.1" />
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.19.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -8,5 +8,9 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Host=localhost;Database=appdb;Username=postgres;Password=app"
|
"DefaultConnection": "Host=localhost;Database=appdb;Username=postgres;Password=app"
|
||||||
|
},
|
||||||
|
"AuthSettings": {
|
||||||
|
"SecretKey": "mysecretkeyqwertyuiopasdfghjklzxcvbnm",
|
||||||
|
"Expires": "00:01:00"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
services:
|
services:
|
||||||
api:
|
api:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: URL-Shortener/Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "5000:8080"
|
- "5000:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
environment:
|
environment:
|
||||||
ConnectionStrings__DefaultConnection: Host=db;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}
|
ConnectionStrings__DefaultConnection: Host=db;Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}
|
||||||
|
AuthSettings__SecretKey: ${JWT_SECRET_KEY}
|
||||||
|
AuthSettings__Expires: "${JWT_EXPIRES}"
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:17
|
image: postgres:17
|
||||||
|
|||||||
Reference in New Issue
Block a user