Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/home from js #1

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.DS_Store
respostas.json
78 changes: 0 additions & 78 deletions respostas.json

This file was deleted.

11 changes: 11 additions & 0 deletions salvar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ app.use(cors());
app.use(express.json());

const caminhoArquivo = path.join(__dirname, 'respostas.json');
const arquivoHome = path.join(__dirname, 'Home.html');

// Cria o arquivo se não existir
if (!fs.existsSync(caminhoArquivo)) {
fs.writeFileSync(caminhoArquivo, '[]');
}

app.get('/', (req, res) => {
try {
const conteudo = fs.readFileSync(arquivoHome, 'utf8');
res.send(conteudo);
} catch (err) {
console.error('Error reading the file:', err);
res.status(500).send('Internal Server Error');
}
});

// ROTA POST - Salvar nova resposta
app.post('/api/respostas', (req, res) => {
const novaResposta = {
Expand Down