endpoints
This commit is contained in:
parent
db80a69351
commit
3529b0a41b
42
Endpoints/UserAccess.cs
Normal file
42
Endpoints/UserAccess.cs
Normal 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}");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
using Emberend.Endpoints;
|
||||
using System.Net;
|
||||
|
||||
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.AddSwaggerGen();
|
||||
|
||||
@ -23,7 +22,6 @@ builder.WebHost.ConfigureKestrel(options =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
@ -31,7 +29,9 @@ if (app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
|
||||
app.MapUserAccessEndpoints();
|
||||
|
||||
//Ne treba jer koristimo nginx kao relay/proxy...
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
|
||||
@ -40,14 +40,12 @@ app.MapGet("/", async (HttpContext context) =>
|
||||
await context.Response.WriteAsync("Hello, alex-api.onlystefan.com");
|
||||
});
|
||||
|
||||
|
||||
app.MapGet("/test", async (HttpContext context) =>
|
||||
{
|
||||
await context.Response.WriteAsync("test");
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.Run();
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user