美文网首页
uglifyjs2|node搭建属于你自己的js压缩混淆加密

uglifyjs2|node搭建属于你自己的js压缩混淆加密

作者: LeeBoot | 来源:发表于2018-09-21 15:57 被阅读0次
    时间紧,任务重,废话不多说了,直接上代码,uglifyJS中用到的参数可以直接在下面的官方参考链接中查阅
    ##service.js
    const http = require('http');
    const queryStr = require('querystring');
    const uglifyJS = require('uglify-js');
    
    const hostname = '192.168.31.242';
    const port = 8089;
    const server = http.createServer((request, response) => {
        let body = '';
        request.on('error', (err) => {
            console.error(err);
            response.statusCode = 404;
            response.end();
        });
        if(request.method.toUpperCase() == 'POST' && request.url == '/mangleCode'){
            request.on('data', function(chunk){
                body += chunk;
            }).on('end', function(){
                response.statusCode = 200;
                response.setHeader('Content-Type', 'application/json');
                const bodyCode = queryStr.parse(body);
                const uglifyCode = uglifyJS.minify(bodyCode.code,{
                    compress:{
                        join_vars:false
                    },
                    output:{
                        comments:'all'
                    }
                });
    
                response.write(JSON.stringify({"code":uglifyCode.code}));
                response.end()
            });
        }else{
            response.statusCode = 404;
            response.end();
        }
    });
    
    server.listen(port, hostname, () => {
        console.log(`Server running at http://${hostname}:${port}/`);
    });
    
    
    • node启动这个服务,之后就可以使用任意的程序去调用了:

    node server.js

    相关文章

      网友评论

          本文标题:uglifyjs2|node搭建属于你自己的js压缩混淆加密

          本文链接:https://www.haomeiwen.com/subject/ewtznftx.html