【Express】防盗链

js 复制代码
const express = require('express');
const app = express();
app.use((req, res, next) => {
  const referer = req.get('referer')
  // console.log(referer)
  if (referer) {
    const url = new URL(referer)
    const hostname = url.hostname
    if(hostname !== 'localhost') {
      res.status(404).send('<h1>404 NOT FOUND</h1>')
      return 
    }
  }
  next()
})
app.use(express.static(__dirname + '/public'))
app.listen(3000, () => {
  console.log('服务器启动成功')
})
相关推荐
深念Y1 小时前
Lenovo XiaoXinAir 14 — 性能模式切换
前端·网络
计算机魔术师1 小时前
Meta突然杀进第一梯队:一个新模型,把AI推理成本打下来8倍
前端
IT_陈寒2 小时前
Redis缓存雪崩把我坑惨了,这次长记性了
前端·人工智能·后端
风骏时光牛马2 小时前
提示词工程:大模型效能挖掘与指令设计实战
前端
仓三2 小时前
Chrome DevTools MCP 上手:让 Coding Agent 自己调试前端页面
前端·chrome devtools·mcp
计算机魔术师2 小时前
扒完Google AI Agent挑战赛的前三名,我发现了一个共同点
前端
独立开发之道2 小时前
【three.js教程】Three.js 运行时更新:矩阵、几何体、材质怎么改才不卡
javascript·矩阵·材质
不可能片场2 小时前
resources/app 为何能覆盖 app.asar
前端·electron
小婉2 小时前
我用 Next.js + React Flow 从零搭建了一个可视化 AI 工作流编排平台
前端·人工智能·node.js