diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 54a5c03..fcabb81 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -3,6 +3,7 @@ using BinaryDad.Notes.Services; namespace BinaryDad.Notes.Controllers { + [ApiController] public class ApiController : ControllerBase { private readonly INoteService noteService; @@ -12,6 +13,7 @@ namespace BinaryDad.Notes.Controllers this.noteService = noteService; } + [Route("note/{noteName}")] public string Note(string noteName) => noteService.GetText(noteName); } } diff --git a/Controllers/NoteController.cs b/Controllers/NoteController.cs index 9f9fe79..839646d 100644 --- a/Controllers/NoteController.cs +++ b/Controllers/NoteController.cs @@ -1,4 +1,4 @@ -using BinaryDad.Notes.Models; +using BinaryDad.Notes.Models; using BinaryDad.Notes.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -15,9 +15,14 @@ public class NoteController : Controller this.noteService = noteService; } - [Route("{noteName=default}")] + [Route("{noteName?}")] public IActionResult Index(string noteName) { + if (string.IsNullOrWhiteSpace(noteName)) + { + noteName = "default"; + } + var model = new ContentModel { CurrentNote = noteName, diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index 0b9f035..4c5fed6 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -4,9 +4,16 @@ { private readonly string filePath; + private static readonly string defaultFilePath = "notes"; + public FileNoteService(IConfiguration configuration) { - filePath = configuration["FileNoteService:ContentFilePath"].Trim(); + filePath = configuration["FileNoteService:ContentFilePath"]; + + if (string.IsNullOrWhiteSpace(filePath)) + { + filePath = defaultFilePath; + } } public string GetText(string noteName) diff --git a/Views/Note/Index.cshtml b/Views/Note/Index.cshtml index f643373..f2a71f9 100644 --- a/Views/Note/Index.cshtml +++ b/Views/Note/Index.cshtml @@ -12,4 +12,11 @@
Saved
-
Updated
\ No newline at end of file +
Updated
+ +@section Scripts +{ + +} diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index 18182aa..ddeaa87 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -1,4 +1,4 @@ -const noteName = document.location.pathname.substring(1); +let noteName = '';//document.location.pathname.substring(1); let connection = new signalR.HubConnectionBuilder() .withAutomaticReconnect() @@ -58,7 +58,7 @@ $(function () { // update content after reconnected connection.onreconnected(function() { - $.get(`api/note?noteName=${noteName}`, function(content) { + $.get(`api/note/${noteName}`, function(content) { $textarea.val(content); showToast('#update-indicator'); console.log('Refreshed after disconnect');