V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
pandashuai
V2EX  ›  Node.js

express-anti-chain ( 防盗链 )

  •  
  •   pandashuai · 2017-04-14 18:23:59 +08:00 · 1825 次点击
    这是一个创建于 2779 天前的主题,其中的信息可能已经有所发展或是发生改变。

    express-anti-chain ( 防盗链 )

    用来保护指定的静态资源不被其它网站使用 gitHub: https://github.com/pandashuai/express-anti-chain npm: https://www.npmjs.com/package/express-anti-chain

    快速上手

    var express = require('express');
    var path = require('path');
    var app = express();
    var anti = require('express-anti-chain');
    app.use(anti({
      // The whitelist that allows the referenced domain name is simple and regular
      ignore: ['localhost:*'],
    
      // Anti-theft chain type
      exts: ['.png', '.jpg', '.jpeg', '.gif', '.swf', '.flv'],
    
      // Anti-theft chain default to the picture  ---- or default: '/images/default.png',
      default: {
        images: '/images/default.png'
      },
    
      // The strict parameter determines whether direct access is blocked
      strict: true,
    
      // Print the log file ---- or log: console.log,
      log: function(url, referer, req){
        console.log('request :' + url + ' from ' + referer + ' was blocked');
      }
      
    }));
    
    // keep anti before use static
    app.use(express.static(path.join(__dirname, 'public')));
    app.set('port', process.env.PORT || 8000);
    
    app.get('/', function(req, res) {
      res.redirect("/index.html");
    });
    
    app.listen(app.get('port'), function() {
      console.log("Express test server listening on http://localhost:" + app.get('port'));
    });
    
    
    1 条回复    2017-04-14 18:26:40 +08:00
    gDD
        1
    gDD  
       2017-04-14 18:26:40 +08:00 via iPhone   ❤️ 2
    盗链是 hot linking …
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3037 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:56 · PVG 18:56 · LAX 02:56 · JFK 05:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.