diff --git a/.vscode/launch.json b/.vscode/launch.json index 47886ae..ed15a24 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -24,7 +24,8 @@ }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" - } + }, + "checkForDevCert": false }, { "name": ".NET Core Attach", diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs new file mode 100644 index 0000000..2112ea0 --- /dev/null +++ b/Controllers/ApiController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using BinaryDad.Notes.Services; + +namespace BinaryDad.Notes.Controllers +{ + public class ApiController : ControllerBase + { + private readonly INoteService noteService; + + public ApiController(INoteService noteService) + { + this.noteService = noteService; + } + + public string Note() => noteService.Get(); + } +} diff --git a/Dockerfile b/Dockerfile index 4b5a78d..3ed91c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,13 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY . . + +RUN dotnet publish "BinaryDad.Notes.csproj" -c Release -o /app/publish /p:UseAppHost=false FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base WORKDIR /app +COPY --from=build /app/publish . + EXPOSE 80 -EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /src -COPY ["BinaryDad.Notes.csproj", "."] -RUN dotnet restore "./BinaryDad.Notes.csproj" -COPY . . -WORKDIR "/src/." -RUN dotnet build "BinaryDad.Notes.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "BinaryDad.Notes.csproj" -c Release -o /app/publish /p:UseAppHost=false - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "BinaryDad.Notes.dll"] \ No newline at end of file diff --git a/Program.cs b/Program.cs index c361739..f97f485 100644 --- a/Program.cs +++ b/Program.cs @@ -9,14 +9,11 @@ builder.Services.AddControllersWithViews(); builder.Services.AddSignalR(); builder.Services.AddSingleton(); -builder.Services.AddSession(options => -{ - options.IdleTimeout = TimeSpan.FromMinutes(30); -}); - builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o => { o.LoginPath = "/login"; + o.Cookie.Name = "NotesUser"; + o.Cookie.MaxAge = TimeSpan.FromDays(3); }); var app = builder.Build(); diff --git a/Views/Login/Login.cshtml b/Views/Login/Login.cshtml index eb41cc8..21b6c85 100644 --- a/Views/Login/Login.cshtml +++ b/Views/Login/Login.cshtml @@ -1,8 +1,4 @@ -@{ - ViewBag.Title = "Login"; -} - -@Html.ValidationSummary() +@Html.ValidationSummary()
diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css index f815c5e..a761322 100644 --- a/wwwroot/css/site.css +++ b/wwwroot/css/site.css @@ -57,7 +57,7 @@ textarea { border-width: 0; } -.dark textarea { +body.dark, body.dark input, body.dark textarea { background-color: #222; color: #ddd; } diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index 267fcf0..62482a4 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -55,6 +55,15 @@ $(function () { showToast('#update-indicator'); }); + // update content after reconnected + connection.onreconnected(function() { + $.get('api/note', function(content) { + $textarea.val(content); + showToast('#update-indicator'); + console.log('Refreshed after disconnect'); + }); + }); + // set dark mode if (window.location.hash == '#dark') { $('body').addClass('dark');