javascript url id在节点js请求参数中找到奇怪的id数据

k5ifujac  于 2023-01-11  发布在  Java
关注(0)|答案(1)|浏览(99)
app.get(['/:id'], function (req, res) {
    
    var _url = req.url
    console.log(url.parse(_url,true));
    
    const pages = fs.readdir('pages', function (err, files) {
        
            let pathname = req.params;
            console.log(pathname.id);
            console.log(pathname);
            console.log(files); 
            console.log('Automotive Design.html'== files[2] );
            console.log(__dirname+'/pages/'+pathname.id);
            

            if(true){
                res.sendFile(path.join(__dirname+'/pages/'+pathname.id));
            }else{
                res.writeHead(404);
            }

            // res.sendFile(path.join(__dirname,'pages',''+pathname.id));

        });

当我在此URL http://localhost:12345/Automotive%20Design.html中运行此代码时,意外地发现了另一个名为“icon”的ID值,我希望找到它并将其删除。

x8diyxa7

x8diyxa71#

这两个是结果。

Automotive Design.html
{ id: 'Automotive Design.html' }
[
  'Automotive Design copy 2.html',
  'Automotive Design copy.html',
  'Automotive Design.html'
]

icons
{ id: 'icons' }
[
  'Automotive Design copy 2.html',
  'Automotive Design copy.html',  'Automotive Design.html'
]

相关问题