express-anti-chain ( 防盗链 )

2017-04-14 18:23:59 +08:00
 pandashuai

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'));
});

1825 次点击
所在节点    Node.js
1 条回复
gDD
2017-04-14 18:26:40 +08:00
盗链是 hot linking …

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/354928

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX