Why I cannot detect whether the http body comes as Base64 encoded despite doing it so?

Dimitrios Desyllas - Apr 5 '23 - - Dev Community

I made a simple app that is detecting whether data is base64 encoded or not:

I made a simplke add that detects whether http body is base64 endoded:


const connect = require('connect')
const base64RegExp = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;
const isBase64 = (str) => base64RegExp.test(str)


const app = connect();


app.use(function(req,res,next){
     
    var body = [];

    req.on('data',(data) =>
    {
        console.log('Getting Body');
        body.push(data)
    });

    req.on('end',() => {
        body = body.toString();
        res.setHeader("Content-Type",'text/plain');

But I fail to do so. Can u help me?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player