我正在尝试获取具有Firebase功能的外部API,并在Angular应用中显示信息。 Angular应用位于Firebase托管上。计费已启用。在localhost上可以正常运行,但在Firebase上无法获取数据。
const functions = require('firebase-functions');
const express = require('express')
, https = require('https')
, bodyParser = require('body-parser')
, app = express()
, cors = require('cors');
app.use(cors());
app.use(bodyParser.json());
const options = {
host: 'api.clashofstats.com',
port: 443,
path: '/clans/YUPJGL2R/',
headers: {
accept: "application/json",
}
};
app.get("/clan",(req, res) => {
const request = https.request(options, (response) =>{
let httpResult = '';
response.on('data', (chunk) => {
httpResult += chunk;
});
response.on('end', () => {
res.send(httpResult);
});
});
request.on('error',(e) => {
console.log('problem with request: ' + e.message);
});
request.end();
});
exports.app = functions.https.onRequest(app);
控制台日志
ERROR e {headers: t, status: 200, statusText: "OK", url: "https://united-clan.cz/clan", ok: false, …}
firebase日志
Function execution took 10 ms, finished with status code: 404
网络
Request URL: https://united-clan.cz/clan
Request Method: GET
Status Code: 200 (from disk cache)
Remote Address: 151.101.65.195:443
Referrer Policy: no-referrer-when-downgrade
https://us-central1-ucweb-224315.cloudfunctions.net/app
Cannot GET null
答案 0 :(得分:1)
您需要在网址中添加一个斜杠-您的问题听起来与此类似: