gpt4 book ai didi

angular - Firebase 和外部 API 404(Firebase 函数)

转载 作者:行者123 更新时间:2023-12-05 05:13:07 34 4
gpt4 key购买 nike

我正在尝试使用 Firebase 函数获取外部 API 并在 Angular 应用程序中显示信息。 Angular 应用程序在 firebase 托管上。计费已启用。在本地主机上,它可以工作,但在 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, …}

火力地堡日志

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

最佳答案

您需要在 url 中添加尾部斜杠 - 您的问题听起来与此类似:

https://github.com/firebase/functions-samples/issues/101

关于angular - Firebase 和外部 API 404(Firebase 函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53961869/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com