Express + SQLite backend with Monaco editor frontend. Supports HTML/CSS/JS, TypeScript, React (JSX/TSX), Vue SFC, and Svelte with live preview, console output, save/fork/share. Includes CSS preprocessors (SCSS, Less), framework-specific compilation (Babel, TypeScript, Svelte compiler), and CDN-loaded runtime libraries for preview rendering.
30 lines
713 B
JavaScript
30 lines
713 B
JavaScript
const BASE = '/api/fiddles';
|
|
|
|
async function request(url, opts = {}) {
|
|
const res = await fetch(url, {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
...opts,
|
|
});
|
|
if (!res.ok) {
|
|
const err = await res.json().catch(() => ({ error: res.statusText }));
|
|
throw new Error(err.error || res.statusText);
|
|
}
|
|
return res.json();
|
|
}
|
|
|
|
export function createFiddle(data) {
|
|
return request(BASE, { method: 'POST', body: JSON.stringify(data) });
|
|
}
|
|
|
|
export function loadFiddle(id) {
|
|
return request(`${BASE}/${id}`);
|
|
}
|
|
|
|
export function updateFiddle(id, data) {
|
|
return request(`${BASE}/${id}`, { method: 'PUT', body: JSON.stringify(data) });
|
|
}
|
|
|
|
export function listFiddles() {
|
|
return request(BASE);
|
|
}
|