localhost:3000,localhost:3000/index和localhost:3000/list三个网址只能访问一个剩下的会显示已拒绝访问
//用于创建网站服务器的模块
const http = require('http');
//app对象就是网站服务器对象
const app = http.createServer();
//当客户端有请求来的时候
app.on('request', (req, res) => {
//获取请求方式
//req.method
// console.log(req.method);
//获取请求地址
//req.url
// console.log(req.url);
if (req.url == '/index') {
res.end('welcome to homepage');
} else if (req.url == '/list') {
res.end('welcome to listpage');
} else {
res.end('not found');
}
if (req.method == 'POST') {
res.end('post');
} else if (req.method == 'GET') {
res.end('get');
}
// res.end('<h2>hello user</h2>')
});
//监听窗口
app.listen(3000);
console.log('网站服务器启动成功');