gpt4 book ai didi

node.js - Firebase 函数 : Upload Error: HTTP Error: 400, 未知错误

转载 作者:行者123 更新时间:2023-12-03 08:27:11 25 4
gpt4 key购买 nike

我尝试将 Angular Universal SSR 应用的服务器端部署到 Firebase Functions,但遇到了错误上传错误:HTTP 错误:400,未知错误

据我了解,当部署是一个巨大的文件(在我的例子中为 438mb)时,此错误经常发生。它如此之大的原因是因为我正在部署网站的本地化版本,因此 dist/browserdist/server 都有 en, defr 目录的内容几乎相同。我该如何解决这个问题?

控制台输出

=== Deploying to 'PROJECT_NAME'...

i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
+ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
+ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing dist directory for uploading...
i functions: packaged dist (438.04 MB) for uploading
! functions: Upload Error: HTTP Error: 400, Unknown Error

Error: HTTP Error: 400, Unknown Error

index.js

const functions = require('firebase-functions');

// Increase readability in Cloud Logging
require("firebase-functions/lib/logger/compat");

const expressApp = require('./server/proxy').app();

exports.ssr = functions
.region('us-central1')
.runWith({})
.https
.onRequest(expressApp);

proxy.ts(编译为js并放入dist/server文件夹中)

import * as express from 'express';
import * as cookieParser from 'cookie-parser';
import { join } from 'path';

export function app() {
const server = express();

server.use(cookieParser());

const languages = ['en', 'de', 'fr'];

languages.forEach((locale) => {
const appServerModule = require(join(__dirname, locale, 'main.js'));
server.use(`/${locale}`, appServerModule.app(locale));
});

server.get('/(:locale(en|fr|de)/)?*', (req, res, next) => {
const { locale } = req.params;
let userLocale = (req.headers['accept-language'] || '').substring(0, 2);

if(!languages.includes(userLocale)) {
userLocale = 'en';
}

if (locale !== userLocale) {
res.redirect(userLocale + req.url);
}
});

return server;
}

function run() {
app().listen(4200, () => {
console.log(`Node Express server listening on http://localhost:4200`);
});
}

run();

最佳答案

我在使用 NextJS 和 firebase 函数时遇到了同样的问题,

这是我的解决方案:

  1. 删除 node_modules 并运行 npm i
  2. 删除缓存文件、外部版本或公共(public)版本
  3. 从 Firebase 面板检查功能控制台注册表(您可以在此处检查您的服务状态/日志)

我希望这对某人有帮助。

关于node.js - Firebase 函数 : Upload Error: HTTP Error: 400, 未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66266314/

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