endpoints

This commit is contained in:
Goran 2026-01-17 22:17:50 +01:00
parent db80a69351
commit 3529b0a41b
2 changed files with 45 additions and 5 deletions

42
Endpoints/UserAccess.cs Normal file
View File

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
namespace Emberend.Endpoints;
public static class UserAccess
{
public static void MapUserAccessEndpoints(this IEndpointRouteBuilder routes)
{
MapGetLogin(routes);
MapGetUserById(routes);
MapGetRegister(routes);
}
private static void MapGetLogin(IEndpointRouteBuilder routes)
{
routes.MapGet("/login", async context =>
{
await context.Response.WriteAsync("/login");
});
}
private static void MapGetRegister(IEndpointRouteBuilder routes)
{
routes.MapGet("/register", async context =>
{
await context.Response.WriteAsync("/register");
});
}
private static void MapGetUserById(IEndpointRouteBuilder routes)
{
routes.MapGet("/user/{id}", async context =>
{
var id = context.Request.RouteValues["id"];
//Dodaj null check ^
await context.Response.WriteAsync($"User: {id}");
});
}
}

View File

@ -1,9 +1,8 @@
using Emberend.Endpoints;
using System.Net; using System.Net;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
@ -23,7 +22,6 @@ builder.WebHost.ConfigureKestrel(options =>
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {
app.UseSwagger(); app.UseSwagger();
@ -31,7 +29,9 @@ if (app.Environment.IsDevelopment())
} }
app.MapUserAccessEndpoints();
//Ne treba jer koristimo nginx kao relay/proxy...
//app.UseHttpsRedirection(); //app.UseHttpsRedirection();
@ -40,14 +40,12 @@ app.MapGet("/", async (HttpContext context) =>
await context.Response.WriteAsync("Hello, alex-api.onlystefan.com"); await context.Response.WriteAsync("Hello, alex-api.onlystefan.com");
}); });
app.MapGet("/test", async (HttpContext context) => app.MapGet("/test", async (HttpContext context) =>
{ {
await context.Response.WriteAsync("test"); await context.Response.WriteAsync("test");
}); });
app.Run(); app.Run();