fix: correct static file serving MIME types and add error handling to standard save

This commit is contained in:
2026-06-23 19:08:08 +00:00
parent 3298cd8c5d
commit f1fc44c58b
2 changed files with 9 additions and 4 deletions
+8 -3
View File
@@ -92,17 +92,22 @@ export const AdminStandards: React.FC<AdminStandardsProps> = ({ apiKey, provider
const parsed = JSON.parse(generatedJson); const parsed = JSON.parse(generatedJson);
parsed.categoria_id = selectedCategory; parsed.categoria_id = selectedCategory;
await fetch('/api/standards', { const res = await fetch('/api/standards', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(parsed) body: JSON.stringify(parsed)
}); });
if (!res.ok) {
const errData = await res.json().catch(() => ({}));
throw new Error(errData.error || `Erro do servidor: ${res.status}`);
}
setGeneratedJson(''); setGeneratedJson('');
setStandardName(''); setStandardName('');
fetchStandards(selectedCategory); fetchStandards(selectedCategory);
} catch (e) { } catch (e: any) {
setJsonError("Erro ao salvar: JSON inválido ou falha na rede."); setJsonError(e.message || "Erro ao salvar: JSON inválido ou falha na rede.");
} }
}; };
+1 -1
View File
@@ -219,7 +219,7 @@ const server = http.createServer((req, res) => {
// --- END STANDARDS CRUD --- // --- END STANDARDS CRUD ---
// Serve static files // Serve static files
let filePath = path.join(DIST_DIR, req.url === '/' ? 'index.html' : req.url); let filePath = path.join(DIST_DIR, pathname === '/' ? 'index.html' : pathname);
// If path doesn't exist, fallback to index.html (SPA routing) // If path doesn't exist, fallback to index.html (SPA routing)
if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) { if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {