我正在尝试使用 url 模块和 http 服务器解析一些 url。
代码如下:
var http = require('http');
var URL = require('url');
var port = 8080;
var server = http.createServer(function(req, res) {
var parsedURL = URL.parse(req.URL, true).pathname;
switch(parsedURL) {
case 'test/myurl':
console.log('Valid URL.');
break;
default:
console.log('404!')
}
});
server.listen(port);
console.log('Service at port: ' + port);
出现以下错误:
TypeError: Parameter 'url' must be a string, not undefined
在这一行:
var parsedURL = URL.parse(req.URL, true).pathname;
有人可以帮忙吗?任何解释将不胜感激。
最佳答案
关于javascript - Node.js TypeError : Parameter 'url' must be a string, 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40054712/