fix: correct static file serving MIME types and add error handling to standard save
This commit is contained in:
@@ -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.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user