【Express】防盗链

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('

404 NOT FOUND

'
) return } } next() }) app.use(express.static(__dirname + '/public')) app.listen(3000, () => { console.log('服务器启动成功') })

你可能感兴趣的:(Express,express,前端,javascript)