这是我的代码在这里..!
const express = require('express');
const app = express();
let myFunc = function (req, res, next) {
console.log('This is middleware');
next();
}
app.use(myFunc);
app.get('/', (req, res) => {
console.log('This is get /');
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Server is running at port 3000....');
});
Run Code Online (Sandbox Code Playgroud)
在此,我创建了一个名为 myFunc 的中间件,但输出并不像我想象的那样
Server is running at port 3000....
This is middleware
This is get /
This is middleware
Run Code Online (Sandbox Code Playgroud)