// 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
相关推荐
海石17 分钟前
📱随时随地大小编:TraeSolo 移动端初体验爱滑雪的码农2 小时前
详细说说React大型项目结构以及日常开发核心语法七牛开发者2 小时前
HTML is the new Markdown:来自 Claude Code 团队的实践@大迁世界3 小时前
43.HTML 事件处理和 React 事件处理有什么区别?CloneCello3 小时前
AI时代程序员认知调整指南ZC跨境爬虫4 小时前
跟着 MDN 学 HTML day_38:(DocumentFragment 文档片段接口详解)@大迁世界5 小时前
41.ShadCN 是什么?它如何和 Tailwind CSS 集成,从而更容易构建可访问且可自定义的 React 组件?千叶风行5 小时前
Text-to-SQL 技术设计与注意事项软件开发技术深度爱好者5 小时前
HTML5+JavaScript读取DOCX 文档完整内容幽络源小助理6 小时前
苹果CMS V10 MXPro V4.5模版下载, 自适应视频主题源码, 幽络源源码