Initial commit: code playground with multi-framework support
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.
This commit is contained in:
29
public/js/api.js
Normal file
29
public/js/api.js
Normal file
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user