【发布时间】:2018-06-20 18:30:29
【问题描述】:
每次我导航到相对路径时,我都会收到以下错误:
TypeError: Parameter "url" must be a string, not undefined
at Url.parse (url.js:103:11)
我的 get 方法如下所示:
app.get('/v1/locations', (req, res) => {
const fixieUrl = url.parse(process.env.FIXIE_URL);
const requestedUrl= url.parse('api.clashofclans.com' + req.path);
const options = {
host: fixieUrl.hostname,
port: fixieUrl.port,
path: requestedUrl.href,
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer **token**',
'Proxy-Authorization': `Basic ${new Buffer(fixieUrl.auth).toString('base64')}`
}
};
我肯定添加了带有 FIXIE_URL 的 .env 文件,那会是什么?
【问题讨论】:
-
您是否尝试过控制台日志 process.env.FIXIE_URL
-
console.log(process.env.FIXIE_URL)在const fixieUrl =之前显示是吗? -
它打印出未定义...我也尝试重新启动 IDE,但仍然显示未定义
-
你导入url模块nodejs.org/api/url.html