3.8 KiB
🚀 Como Iniciar o Servidor Local
❌ PROBLEMA: Erro CORS
Quando você abre index.html diretamente no navegador (file:///), o navegador bloqueia o carregamento de arquivos CSV por segurança (política CORS).
Erro típico:
Access to fetch at 'file:///...' has been blocked by CORS policy
✅ SOLUÇÃO: Usar Servidor Web Local
Você PRECISA usar um servidor web local para o aplicativo funcionar corretamente.
🎯 Opção 1: Python (Recomendado)
Windows:
Método 1: Duplo clique
- Duplo clique em
server.bat - Aguarde o servidor iniciar
- Acesse: http://localhost:8000
Método 2: PowerShell/CMD
python server.py
Linux/Mac:
python3 server.py
🎯 Opção 2: Python Simples (Sem arquivo)
Python 3:
python -m http.server 8000
Python 2:
python -m SimpleHTTPServer 8000
Acesse: http://localhost:8000
🎯 Opção 3: Node.js (http-server)
Instalar (uma vez):
npm install -g http-server
Executar:
http-server -p 8000
Acesse: http://localhost:8000
🎯 Opção 4: PHP
php -S localhost:8000
Acesse: http://localhost:8000
🎯 Opção 5: Live Server (VS Code)
- Instalar extensão "Live Server" no VS Code
- Clicar com botão direito em
index.html - Selecionar "Open with Live Server"
- Abre automaticamente no navegador
🎯 Opção 6: Vercel Dev (Para testar deploy)
npm install -g vercel
vercel dev
Acessa automaticamente no navegador
✅ Verificar se Funcionou
Após iniciar o servidor:
- Abra: http://localhost:8000
- Vá para: MATERIAIS → Catálogo de Perfis → Cantoneiras
- Clique: "🔄 Carregar Dados"
- Veja: 39 cantoneiras devem aparecer
- Console: Sem erros CORS
🐛 Troubleshooting
Erro: "Porta 8000 já está em uso"
Solução 1: Usar outra porta
python -m http.server 8001
Solução 2: Matar processo na porta 8000
# Windows
netstat -ano | findstr :8000
taskkill /PID <PID> /F
# Linux/Mac
lsof -ti:8000 | xargs kill -9
Erro: "Python não encontrado"
Solução: Instalar Python
- Windows: https://www.python.org/downloads/
- Linux:
sudo apt install python3 - Mac:
brew install python3
Erro: "Comando não encontrado"
Solução: Verificar se Python está no PATH
# Verificar instalação
python --version
# ou
python3 --version
📊 Comparação de Servidores
| Servidor | Velocidade | Facilidade | Recomendado |
|---|---|---|---|
| Python | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ SIM |
| Node.js | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ✅ SIM |
| PHP | ⭐⭐⭐ | ⭐⭐⭐ | ⚠️ OK |
| Live Server | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ SIM |
| Vercel Dev | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ✅ SIM |
🎯 Recomendação Final
Para Desenvolvimento:
Use server.py ou Live Server (VS Code)
Para Testes de Deploy:
Use vercel dev ou netlify dev
Para Produção:
Faça deploy no Vercel ou Netlify
🚀 Após Iniciar o Servidor
- ✅ Acesse http://localhost:8000
- ✅ Vá para Cantoneiras
- ✅ Clique em "🔄 Carregar Dados"
- ✅ Veja os 39 itens aparecerem
- ✅ Sem erros CORS no console!
📝 Nota Importante
NUNCA abra index.html diretamente no navegador!
❌ ERRADO: file:///I:/NOCODE/STEELCHK/index.html
✅ CORRETO: http://localhost:8000/index.html
O erro CORS SEMPRE vai acontecer se você abrir diretamente.
Inicie o servidor e teste novamente! 🚀