我已经在 Heroku 上部署了我的 Node.js Koa API 应用程序。我正在调用 USAJOB.gov API,它可以在我的本地主机上运行。但是,在 Heroku 上,我收到此错误:
You don't have permission to access "http://data.usajobs.gov/$(SERVE_403)/api/search?" on this server.
这是我的 Koa 路由器片段:
router.get('/jobs', async (ctx) => {
const { keyword, location } = ctx.query;
const url = `https://data.usajobs.gov/api/search?
Keyword=${keyword}&LocationName=${location}`;
const host = 'data.usajobs.gov';
const userAgent = '<redacted>';
const authKey = '<redacted>';
const headers = {
Host: host,
'User-Agent': userAgent,
'Authorization-Key': authKey,
};
await fetch(url, {
headers,
method: 'GET',
});
}