On the problem of intercepting requests by node

I use routing in app.js

var headbarRouter = require("./routes/headbar");
app.use("/headbar", headbarRouter);

then write this in routes/headbar.js

router.get("/", function(req, res, next) {
    console.log("--------")
  res.render("headbar", { title: "Express" });
});

my understanding is that requests that start with headbar will be intercepted, and then render to headbar.ejs
, but that"s what I wrote in index.ejs

.
<script src="/headbar.js"></script>

isn"t this also a request? Why did you not intercept and go to headbar.ejs, but reported an error of 404

?

clipboard.png

Mar.22,2021

app.use ('/ headbar') here the matching rule for / headbar is to match the first part of a request path-- the content between the first two / symbols. If the prefix matches, the prefix of that path means the first part of the path . For / headbar.js , it is headbar.js , which obviously does not match headbar . / headbar can handle requests such as / headbar or / headbar/* . The


script tag requests js files, belongs to static files, and walks through the static directory configured by static. Do not walk by

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-16deded-892c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-16deded-892c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?