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('服务器启动成功')
})