// index.js
const http = require('http')
const fs = require('fs')
const path = require('path')
const server = http.createServer((req, res) => {
let filePath = path.resolve(__dirname, req.url === '/' ? `index.html` : '1.jpg')
res.writeHead(200, {
'Content-Type': req.url === '/' ? 'text/html; charset=utf-8' : 'image/png',
'Cache-Control': 'max-age=86400', // 设置缓存缓存一天
})
const fileStream = fs.createReadStream(filePath)
return fileStream.pipe(res)
})
server.on('clientError', (err, socket) => {
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
})
server.listen(8080, () => {
console.log(`opened server on http://localhost:${server.address().port}`)
})
node强缓存
猛男敲代码2024-09-14 17:04
相关推荐
Mh3 小时前
Three.js 实现 3D 汽车交互2.0版本2601_958352905 小时前
I2S转模拟音频,真的只要5个引脚+1个电容?workflower7 小时前
如何培养FDE-3小小测试开发7 小时前
rsync 源路径少一个斜杠,--delete 删的就不是你以为的那一层智购科技无人售货机工厂店8 小时前
自动售货机刷脸支付集成实战:活体检测与合规门槛~YH夕水10 小时前
我把颜色选择器拆成了 15 个插件,最后长成了 22 个包大今野10 小时前
2026 专转本计算机|移动互联网关键技术:SOA、Web2.0 与 HTML5 考点全解(附例题)JudithHuang10 小时前
Vue3 与后端联调:代理、Mock 与接口约定Swot11 小时前
工具转换 vs LLM 转换:以 Markdown 转 AsciiDoc 为例