// 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
相关推荐
岁月宁静2 小时前
深度定制:在 Vue 3.5 应用中集成流式 AI 写作助手的实践心易行者3 小时前
10天!前端用coze,后端用Trae IDE+Claude Code从0开始构建到平台上线saadiya~3 小时前
ECharts 实时数据平滑更新实践(含 WebSocket 模拟)fruge3 小时前
前端三驾马车(HTML/CSS/JS)核心概念深度解析百锦再4 小时前
Vue Scoped样式混淆问题详解与解决方案烛阴4 小时前
Lua 模块的完整入门指南浪里行舟5 小时前
国产OCR双雄对决?PaddleOCR-VL与DeepSeek-OCR全面解析znhy@1235 小时前
CSS易忘属性瓜瓜怪兽亚5 小时前
前端基础知识---AjaxAI智能研究院5 小时前
(四)从零学 React Props:数据传递 + 实战案例 + 避坑指南