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);
|
||||
parsed.categoria_id = selectedCategory;
|
||||
|
||||
await fetch('/api/standards', {
|
||||
const res = await fetch('/api/standards', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(parsed)
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({}));
|
||||
throw new Error(errData.error || `Erro do servidor: ${res.status}`);
|
||||
}
|
||||
|
||||
setGeneratedJson('');
|
||||
setStandardName('');
|
||||
fetchStandards(selectedCategory);
|
||||
} catch (e) {
|
||||
setJsonError("Erro ao salvar: JSON inválido ou falha na rede.");
|
||||
} catch (e: any) {
|
||||
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 ---
|
||||
|
||||
// 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 (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
|
||||
|
||||
Reference in New Issue
Block a user