Minha dúvida se dá devido ao seguinte problema, mesmo após configurar a rota form/:id para receber o livro do banco de dados as informações do mesmo não são dispostas no form e ainda , segue o codigo:
Função de busca:
searchById(id) {
return new Promise((resolve, reject) => {
this._db.get(
`
SELECT *
FROM livros
WHERE id = ?
`,
[id],
(err, book) => {
if (err) {
return reject('It was not possible to find this book.');
}
return resolve(book);
}
);
});
}
rota configurada:
app.get('/books/form/:id', function(req, res) {
const id = req.params.id;
const bookDAO = new BookDAO(db);
bookDAO.searchById(id)
.then(book =>
res.marko(
require('../views/books/form/form.marko'),
{ book: book }
)
)
.catch(err => console.log(err));
});
form.marko:
<html>
<body>
<h1>Books Registration</h1>
<form action="/books" method="post">
<input type="hidden" id="id" name="id" value="${data.book.id}"/>
<div>
<label for="title">Title:</label>
<input type="text" id="title" name="title" value="${data.book.title}" placeholder="Insert book's title" />
</div>
<div>
<label for="price">Price:</label>
<input type="text" id="price" name="price" value="${data.book.price}" placeholder="00.00" />
</div>
<div>
<label for="description">Description:</label>
<textarea cols="20" rows="10" id="description" name="description" value="${data.book.description}" placeholder="Describe the book."></textarea>
</div>
<input type="submit" value="Save" />
</form>
</body>
</html>
e quando acesso a rota /form (sem o id) recebo o erro:
_http_outgoing.js:518
throw new ERR_HTTP_HEADERS_SENT('set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client