const http = require('http')
const fs = require('fs')
const path = require('path')
http.createServer((req, res) => {
const url = req.url
let fpath = ''
if (url === '/') {
fpath = path.join(__dirname, './yeliomik/index.html')
} else {
fpath = path.join(__dirname, './yeliomik', url)
}
console.log(`请求的地址是${fpath}`)
fs.readFile(fpath, (err, suc) => {
if (err) {
res.end(`404 Not fount
`)
}
res.end(suc)
})
}).listen('5000', () => {
console.log("监听端口为5000")
})
fs.readFile回调给浏览器的东西,如果是图片和视频加载完成后浏览器就会报错,再重新加载,如何解决这个问题
完整的应该是这样的
用的vscode编译器吧,下载个扩展插件就可以了