当我尝试在 .env 文件中添加安全 API 密钥时,出现以下错误:
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-RapidAPI-Host"
at ClientRequest.setHeader (node:_http_outgoing:579:3)
at new ClientRequest (node:_http_client:256:14)
at Object.request (node:https:353:10)
Run Code Online (Sandbox Code Playgroud)
下面是我的代码:
const axios = require("axios");
const BASE_URL = `https://mashape-community-urban-dictionary.p.rapidapi.com`
module.exports = {
getCompatibility: (yourSearch) => axios({
method:"GET",
url : BASE_URL + `/define`,
headers: {
'X-RapidAPI-Host': process.env.rapidapi_host,
'X-RapidAPI-Key': process.env.Rrapidapi_key
},
params: {
term: yourSearch
}
})
}
Run Code Online (Sandbox Code Playgroud)
我的环境文件:
rapidapi_host={my secure host}
rapidapi_key={my secure key}
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么会发生这种情况?