How rewrite URLs in Node.js with express-urlrewrite

I try to rewrite my path 'mywebsite/public/pages' to 'mywebsite/pages'.

I do this but nothing happend :

rewrite = require('express-urlrewrite');

const allowed = [".js", ".css", ".png", ".jpg", ".jpeg", ".pdf", ".docx", ".svg", ".ico", ".xml", ".gif"];


app.get("*", (req, res) => {
  if (allowed.filter(ext => req.url.indexOf(ext) > 0).length > 0) {
    console.log(req.url);
    res.sendFile(path.resolve(`${__dirname}/public${req.url}`));
   
  } else {
    console.log(__dirname);
    res.sendFile(path.join(__dirname, "/public/index.html"));
    
  }
  
});

//I try this
app.use(rewrite(/^\/public\/(.*)/, '/$1'));
//Or this
app.use(rewrite('/public/*', '/$1'));