// 用于创建网站服务器的模块
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'||req.url=='/') {
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')
}
});
//必须监听端口
app.listen(3000, function () {
console.log('网站的服务器启动成功');
});
到底说的是注释哪个if语句啊。代码里有if...else if
一条接口请求给了两个响应导致的??