我试图使用url模块和http服务器解析一些网址。
代码如下:
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;
任何人都可以提供帮助?任何解释都将不胜感激。