fixed SSE Connection error and Rust error when compiling (last brace in /src/markdown.rs)
Some checks failed
Deploy / build-and-deploy (push) Failing after 2s

also updated the markdown post that you see upon entering.
This commit is contained in:
2025-06-29 15:56:30 +02:00
parent 6b5705680a
commit b0033a5671
3 changed files with 105 additions and 58 deletions

View File

@@ -673,8 +673,4 @@ pub fn checkhealth() -> HealthReport {
cache_stats_count,
errors,
}
}
cache_stats_count,
errors,
}
}
}

View File

@@ -434,7 +434,6 @@ Key API endpoints include:
All API routes are implemented using Next.js API routes and are available out of the box. For more details, check the code in the `src/app/api/posts/` directory.
--
## Train of Thought for this Project and Todo
@@ -446,29 +445,24 @@ If you have seen this is not very mindfull of browser resources tho.
|-------|----|
|<span style="color:green;">Done</span>|**Rust Parser for Markdown**|
|<span style="color:lightblue;">LTS</span>|_Long Term Support and upkeep_|
|<span style="color:red;">Not Done</span>|Full Inline _CSS_ Support for **HTML**|
|<span style="color:lime;">Partially Done</span>|**Caching with Rust**|
|<span style="color:green;">Done</span>|Full Inline _CSS_ Support for **HTML**|
---
## <font color="red">R</font><font color="orange">e</font><font color="yellow">c</font><font color="green">e</font><font color="blue">n</font><font color="purple">t</font> <font color="red">C</font><font color="orange">h</font><font color="yellow">a</font><font color="green">n</font><font color="blue">g</font><font color="purple">e</font><font color="red">s</font>
## Recent Changes
<img src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Original_Ferris.svg" style="height:50px;width:90px;display:block;margin:0 auto;" alt="cute lil guy">
<p style="display:block;margin:0 auto;text-align:center;font-style:italic;font-weight:bold;">Ferris the Cutie</p>
<br />
If you have noticed the Project has switched to a more reliable and _faster_ **Rust** Markdown-Parser!
If you are wondering:
### Caching:
Recently the _Rust Parser recived a update_ which introduced **Caching using RAM**. This is not yet _fully implemented_, but it is in the works.
#### <u>Why?</u>
- To make **loading times** / _compile times_ (For the **HTML of the Pages** || _slugification_) of posts quicker.
#### <u>What changed?</u>
- The **RustMarkdownParser** (_RMP_) only really changed the **Architecture** of the _Parsing for Markdown Files_. If you are wondering how _fast_ the Parser is then have a look at the **Admin-Panel**, which also _changed quite a lot_.
#### <u>Do I need to do anything?</u>
- If you havent already, then **Update** the Blog! Blogging stays the same. No difference. Just _🗲 faster 🗲_.
### Recursive Folder-Scanning via Rust:
The Rust Parser was **not implemented fully** _(28.JUN.2025)_. **BUT**, I can proudly state that since _29.JUN.25_ **The Rust Parser is parsing** with ease and with _BLAZING SPEEDS_
### Fixed SSE CORS Connection:
Since Ages the **SSE Streaming _was_ broken**, now its fixed (see _@src/app/api/posts/stream/route.ts_). This works fine, needs some work still.
<br />

View File

@@ -8,50 +8,107 @@ export const runtime = 'nodejs';
// Store connected clients
const clients = new Set<ReadableStreamDefaultController>();
// Handle CORS preflight requests
export async function OPTIONS(request: NextRequest) {
return new NextResponse(null, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Cache-Control, Content-Type',
'Access-Control-Max-Age': '86400',
},
});
}
export async function GET(request: NextRequest) {
const stream = new ReadableStream({
start(controller) {
// Add this client to the set
clients.add(controller);
try {
const stream = new ReadableStream({
start(controller) {
// Add this client to the set
clients.add(controller);
// Send initial connection message
controller.enqueue(`data: ${JSON.stringify({ type: 'connected', message: 'SSE connection established' })}\n\n`);
// Send initial connection message
try {
controller.enqueue(`data: ${JSON.stringify({ type: 'connected', message: 'SSE connection established' })}\n\n`);
} catch (error) {
console.error('Error sending initial message:', error);
clients.delete(controller);
return;
}
// Set up file watcher if not already set up
if (clients.size === 1) {
watchPosts(() => {
// Notify all connected clients about the update
const message = JSON.stringify({ type: 'update', timestamp: new Date().toISOString() });
clients.forEach(client => {
try {
client.enqueue(`data: ${message}\n\n`);
} catch (error) {
// Set up file watcher if not already set up
if (clients.size === 1) {
try {
watchPosts(() => {
// Notify all connected clients about the update
const message = JSON.stringify({ type: 'update', timestamp: new Date().toISOString() });
const clientsToRemove: ReadableStreamDefaultController[] = [];
clients.forEach(client => {
try {
client.enqueue(`data: ${message}\n\n`);
} catch (error) {
// Mark client for removal
clientsToRemove.push(client);
}
});
// Remove disconnected clients
clients.delete(client);
}
});
});
}
clientsToRemove.forEach(client => {
clients.delete(client);
});
// Stop watching if no clients are connected
if (clients.size === 0) {
stopWatching();
}
});
} catch (error) {
console.error('Error setting up file watcher:', error);
}
}
// Clean up when client disconnects
request.signal.addEventListener('abort', () => {
clients.delete(controller);
// Stop watching if no clients are connected
// Clean up when client disconnects
request.signal.addEventListener('abort', () => {
clients.delete(controller);
// Stop watching if no clients are connected
if (clients.size === 0) {
stopWatching();
}
});
},
cancel() {
// Handle stream cancellation - we can't access the specific controller here
// The abort event handler will handle cleanup for the specific controller
if (clients.size === 0) {
stopWatching();
}
});
}
});
}
});
return new NextResponse(stream, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Cache-Control'
}
});
return new NextResponse(stream, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Connection': 'keep-alive',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Cache-Control, Content-Type',
'X-Accel-Buffering': 'no', // Disable nginx buffering
},
});
} catch (error) {
console.error('SSE route error:', error);
return new NextResponse(
JSON.stringify({ error: 'Internal server error' }),
{
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
}
);
}
}