const http= require('http')
const server = http.createServer()
server.on('request', (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
let mess = '<h1>404 页面请求失败</h1>'
if(req.url === '/' || req.url === '/home') {
mess = '<h1>首页</h1>'
} else if (req.url === '/about') {
mess = '<h1>关于</h1>'
}
res.end(mess)
})
server.listen(3000, () => {
console.log('ok')
})
console.log('服务器创建成功')
node根据请求路径返回不同的数据
最新推荐文章于 2024-07-24 10:40:52 发布