// 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
相关推荐
api7725 分钟前
1688商品详情API返回值中的售后保障与服务信息赵广陆34 分钟前
SprinBoot+Vue门诊管理系统的设计与实现华山令狐虫1 小时前
el-tabs 样式修改史努比的大头3 小时前
前端开发深入了解webpackDovir多多3 小时前
渗透测试入门学习——php与mysql数据库连接、使用session完成简单的用户注册、登录B.-3 小时前
Remix 学习 - @remix-run/react 中主要的 hooks小刘|3 小时前
《实现 HTML 图片轮播效果》罗_三金4 小时前
微信小程序读写NFC标签(实现NFC标签快速拉起小程序)实战大大。5 小时前
el-input 只能输入数字和一个小数点,或者只能输入正整数盼盼盼5 小时前
如何避免在使用 Context API 时出现状态管理的常见问题?