Bored Student
Bored Student
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Bored Student on 11/19/2024 in #questions
How to type react element arguments
I want to take a string like this
const Example = (guid : string) => { ... }
const Example = (guid : string) => { ... }
but when i call it like this it says
Type { guid: string; } is not assignable to type string
Type { guid: string; } is not assignable to type string
So i try to use an anonymous class kind of thing
const Example = ({guid : string}) => { ... }
const Example = ({guid : string}) => { ... }
But that's some mess. The following works
const Example = (input : {guid : string}) => { ... }
const Example = (input : {guid : string}) => { ... }
But that is ugly as hell, how do i write that properly ??
6 replies
TTCTheo's Typesafe Cult
Created by Bored Student on 11/16/2024 in #questions
How to get OpenAi API Key
No description
2 replies
TTCTheo's Typesafe Cult
Created by Bored Student on 11/16/2024 in #questions
Add React to .NET Api
I have written a .NET Api and now i want to create a web app that uses it. And i want to set it up that the .Net server serves that app on the / route (or better any out that's not /api/*). There is some info from microsoft but that almos exclusively to creating a new combined empty project with an VisualStudio template, but i don't want a new empty .NET app and i don't have VS.
7 replies
TTCTheo's Typesafe Cult
Created by Bored Student on 10/7/2024 in #questions
From Post to API
Is it possible to post a from to an API Endpoint but stay on the Page without JS ? I have a project that requires me to use JSP (without JS). And I want to add data to a list, and keep that list in view.
6 replies
CC#
Created by Bored Student on 5/22/2024 in #help
How to Dockerize
I have the following docker file
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet","ControllerApi.dll"]
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet","ControllerApi.dll"]
pretty much copy paste from Microsoft https://learn.microsoft.com/de-de/dotnet/core/docker/build-container?tabs=linux&pivots=dotnet-8-0 but i encounter an error i dont have in any other environment about not finding serilog
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Serilog.Sinks.File, Version=5.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified.
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Serilog.Sinks.File, Version=5.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified.
I looked that my .csproj only reference serilog nuget package not the dll directly, and i'm not even using the file sink
3 replies
TTCTheo's Typesafe Cult
Created by Bored Student on 5/17/2024 in #questions
Whats /aab
Lately I've seen a lot of request in my server log probing for some obvious securit overgishts like GET [host]/.env or GET [host]/wp-admin/setup-config.php but there are some I don't recongnize what they are going for e.g. GET [host]/aab8 GET [host]/aab9``GET [host]/ab2h anyone know if they mean anything ? if so what, just curious
2 replies
CC#
Created by Bored Student on 5/8/2024 in #help
API Endpoint is Invoked with `null` Argument
I am sending the following call
const requestOptionsUpdateAddress = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Authorization": "Bearer " + token,
},
body: JSON.stringify({
"lable" : nameInput.value,
"poBox" : typeDropdown.value,
"poNumber" : packstationVal,
"town": cityInput.value,
"zipCode": zipInput.value,
"road": streetNameInput.value,
"houseNumber" : streetNumberInput.value,
"country": countryInput.value,
})
}
const responseUpdateAddress = await fetch(baseUri.concat("/user/updateAddress"), requestOptionsUpdateAddress);
const requestOptionsUpdateAddress = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Authorization": "Bearer " + token,
},
body: JSON.stringify({
"lable" : nameInput.value,
"poBox" : typeDropdown.value,
"poNumber" : packstationVal,
"town": cityInput.value,
"zipCode": zipInput.value,
"road": streetNameInput.value,
"houseNumber" : streetNumberInput.value,
"country": countryInput.value,
})
}
const responseUpdateAddress = await fetch(baseUri.concat("/user/updateAddress"), requestOptionsUpdateAddress);
to the Following API endpoint
c#
[HttpPost("/user/updateAddress")]
[Authorize]
public async Task<IResult> UpdateSingleAddress([FromBody] UpdateAddress ad)
{
if (ad == null)
{
var buffer = new byte[HttpContext.Request.ContentLength ?? 0];
var read = await HttpContext.Request.Body.ReadAsync(buffer);
var body = Encoding.UTF8.GetString(buffer);
_logger.LogWarning("No data provided : {0}", body);
return Results.Problem("No data provided", statusCode: 400, title: "No data provided");
}
...
}
c#
[HttpPost("/user/updateAddress")]
[Authorize]
public async Task<IResult> UpdateSingleAddress([FromBody] UpdateAddress ad)
{
if (ad == null)
{
var buffer = new byte[HttpContext.Request.ContentLength ?? 0];
var read = await HttpContext.Request.Body.ReadAsync(buffer);
var body = Encoding.UTF8.GetString(buffer);
_logger.LogWarning("No data provided : {0}", body);
return Results.Problem("No data provided", statusCode: 400, title: "No data provided");
}
...
}
Yet ad is null and this if triggers. First Question : why doesn't the Middleware already stop an Empty request ? Second Question : I confirmed with the Browser DevTools that the request isn't actually empty, so where does my data go ? DTO Class for reference
c#
public class UpdateAddress
{
public string Lable { get; set; }
public bool POBox { get; set; }
public int? PONumber { get; set; }

public string Town { get; set; }
public int ZipCode { get; set; }
public string Road { get; set; }
public string HouseNumber { get; set; }
public string Country { get; set; }
}
c#
public class UpdateAddress
{
public string Lable { get; set; }
public bool POBox { get; set; }
public int? PONumber { get; set; }

public string Town { get; set; }
public int ZipCode { get; set; }
public string Road { get; set; }
public string HouseNumber { get; set; }
public string Country { get; set; }
}
13 replies
TTCTheo's Typesafe Cult
Created by Bored Student on 4/22/2024 in #questions
React Build page
I wanted to deploy a react app to nginx, with the following commands
# [...] repo is fetched and env vars are set
cd $REPO_PATH/Frontend
npm install
npm run build

if [ $? -eq 0 ];
then
echo "Build Frontend, Deploying"
sudo rm -rf /var/www/html/*
sudo cp -r $REPO_PATH/Frontend/build/* /var/www/html/
else
echo "Failed to Build frontend, Kept the old one alive"
fi
# [...] repo is fetched and env vars are set
cd $REPO_PATH/Frontend
npm install
npm run build

if [ $? -eq 0 ];
then
echo "Build Frontend, Deploying"
sudo rm -rf /var/www/html/*
sudo cp -r $REPO_PATH/Frontend/build/* /var/www/html/
else
echo "Failed to Build frontend, Kept the old one alive"
fi
But i found out that npm run build only produces an index.html and i get error 404 if I navigate on the deployed page. Is there a way to fix this without changing the code, it's not mine.
2 replies
CC#
Created by Bored Student on 1/26/2024 in #help
Neat String interpolation
C#
foreach(file in files){
//Process file
Console.WriteLine($"Processed File [{file.Nr}/{files.Count}]");
}
C#
foreach(file in files){
//Process file
Console.WriteLine($"Processed File [{file.Nr}/{files.Count}]");
}
I have this little something, and I want the counter to stay fixed width so [ 1/50] instead of [1/50] how can I do this ? As simple as possible, I just want it to look neat not write a TUI framework. I found $"{val , fixedWidth}" but that only works with constants so it can't adapt if I reach 100 files.
16 replies
CC#
Created by Bored Student on 1/18/2024 in #help
Type Inference strategies?
I'm generating Class Definition from XML. And currently I just save the Value strings. But I want stricter validation abilities, so I want to find suitable base types, e.g. detect number types. Do you have any ideas how to go about that efficiently and how to balance strictness vs. information loss in small types ?
1 replies
CC#
Created by Bored Student on 1/15/2024 in #help
Propagate Changes to WPF
I'm using WPF with Unity Container and Prism. I've got a save button which is supposed to activate once I have data. I log MyCommand.CanExecute() which is true but it remains disabled in the GUI. MyCommand.RaiseCanExecuteChange() does not exist in Prism. (Or at least can't be resolved)
2 replies