response.statusCode = 200const filePath = path === '/' ? '/index.html' : path // 默认index.html// 识别后缀const index = filePath.lastIndexOf('.')const suffix = filePath.substring(index)const fileType = {".html": "text/html",".js": "text/javascript",".css": "text/css",".json": "text/json",".png": "image/png",".jpg": "image/jpeg"}response.setHeader('Content-Type',`${fileType[suffix] || 'text/html'};charset=utf-8`)// 处理错误let contenttry{content = fs.readFileSync(`./public${filePath}`)}catch(error){content = "文件不存在"response.statusCode = 404}response.write(content)response.end()
