As a student diving into Express, I have come across a slight issue that I need help with.
Within my routes/index.js file, the following code block exists:
router.post('/orders.html', function(req, res, next) {
var fhead = __dirname+ "/../views/head.html";
var head = fs.readFileSync(fhead, 'utf-8');
var ftail = __dirname+ "/../views/tail.html";
var tail = fs.readFileSync(ftail, 'utf-8');
//Do I need to add this???
//res.render('index', function (err, html) {
// if(err) throw err; }
var item = req.body.item;
var quantity = req.body.quanty;
var name = req.body.name;
var rep = item + " was ordered " + quantity +
" times by " + name;
res.send(head + rep + tail);
});
I am facing an issue where the CSS is not displaying correctly when I open the post orders.html page. Everything seems fine except for the CSS styling. Surprisingly, the head.html and tail.html files work perfectly well!
head.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TITLE</title>
<link rel="stlesheet" style="text/css" href="bs/css/bootstrap.min.css">
<link rel="stylesheet" style="text/css" href="../public/css/style.css">
<script type="text/javascript" src="../javascript/popup.js"></script>
</head>
<body>
<header>
<a href="index.html" target="_self">
<img src="../public/images/logo.png" alt="Logo"></a>
<h1 id="titre">SHOP</h1>
<nav class="navbar navbar-default">
Nav bar
<ul class="horizontalbar">
<li onclick="popup()">Me</li>
<li><a href="contact.html" target="_self">Contact</a></li>
<li><a href="orders.html" target="_self">Orders</a></li>
</ul>
</nav>
</header>
<div class="container">
<h1>Wellecome!</h1>
<p1>babla</p1>
tail.html
<link rel="stylesheet" style="text/css" href="../public/css/tail.css">
<div class="foot">
<span>textext</span>
<a href = "mailto: mail@com">Me</a>
</div>
</div>
</body>
</html>
Could anyone please assist me in resolving why the CSS is failing to load?
I also have another question - should I include all HTML code or just the body section in my index, orders, contact HTML files? By including only the body, I can call head + THE PAGE + tail which reduces repeated code. Is this approach advisable, or is it better to write everything out every time?
Thank you in advance!