// 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
相关推荐
憧憬成为web高手5 小时前
ACTF 12307复现wordbaby6 小时前
Axios 上传大文件崩溃:鸿蒙 RNOH 下 XHR 返回空响应头引发的"假失败"wordbaby6 小时前
React Native 列表分页实战:下拉刷新与上拉加载的工程化方案wordbaby7 小时前
脱离 Tab 栏的艺术:React Native 全屏子页面的导航架构实践陈随易7 小时前
Redis 8.8发布,一定要更新wordbaby7 小时前
React Native 新架构落地鸿蒙:跨三端政务级应用的工程实践与深度复盘excel9 小时前
为什么我推荐使用 Termius:现代 SSH 工具的完整体验ZC跨境爬虫9 小时前
模块化烹饪小程序开发日记 Day7:(菜谱详情接口开发与JSON数据读取全流程)এ慕ོ冬℘゜9 小时前
JS 前端基础面试题LaughingZhu9 小时前
Product Hunt 每日热榜 | 2026-05-25