Код работает верно, при изменении конфига выводит то что в конфиге, но проверка не проходит.
server.js
mport express from 'express';
import { logger } from './middleware.js';
const configString = ':date :url';
const server = express();
server.use (logger (configString));
server.get('/', (req, res) => {
res.send('Learning to use middleware!');
});
server.get('/about', (req, res) => {
res.send(`I'm going to become a JS Developer in ${new Date().getFullYear()}!`);
})
export { server };
middleware.js
import { getFormattedDate } from "./functions.js";
export const logger = (configString) => {
return (req, res, next) => {
let outString='';
if (configString.includes (':date')){
outString=outString +(`${getFormattedDate()} `);
}
if (configString.includes (':method')){
outString=outString +(`Received ${req.method} `);
}
if (configString.includes (':url')){
outString=outString +(`URL: ${req.url}`);
}
console.log(outString);
next ();
}
};