Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async fn start_server(state: AppState, cli_args: Args) -> Result<()> {
.with_state(state)
// Serve the assets folder from the repo
.nest_service(
&format!("/{asset_path}"),
"/assets",
ServeDir::new(format!("repo/{asset_path}")),
)
// Serve the frontend files
Expand Down
22 changes: 10 additions & 12 deletions frontend/src/lib/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import { Renderer, marked, type TokensList } from 'marked';
import DOMPurify from 'dompurify';
import { ToastType, addToast, dismissToast } from './toast';
import { dev } from '$app/environment';
import { get } from 'svelte/store';
import { currentFile } from './main';
import { currentFile, apiAddress } from './main';

/**
* When the rendered file is missing a valid frontmatter header, then an error toast is displayed.
Expand All @@ -28,16 +27,15 @@ export async function renderMarkdown(input: string, output: HTMLElement): Promis
const rawTokens: TokensList = marked.lexer(input);
stripFrontMatter(rawTokens);
// rewrite image urls to point to the correct location
if (dev) {
marked.walkTokens(rawTokens, (t) => {
if (t.type !== 'image') {
return;
}
if (t.href.startsWith('/')) {
t.href = 'http://localhost:8080' + t.href;
}
});
}
marked.walkTokens(rawTokens, (t) => {
if (t.type !== 'image') {
return;
}
t.href = t.href.replace(/^(?:\.\.\/)+/, '/');
if (t.href.startsWith('/')) {
t.href = apiAddress + t.href;
}
});
const cleanedOutput: string = DOMPurify.sanitize(await marked.parser(rawTokens));
if (DOMPurify.removed.length > 0) {
console.warn('Possible XSS detected, modified output: ', DOMPurify.removed);
Expand Down