这是项目结构:
我的网站写在 next.js 上。为了使用 next-i18next 和发送电子邮件,有 src/app/server/server.js 。
const express = require("express");
const next = require("next");
const nextI18NextMiddleware = require("next-i18next/middleware");
var bodyParser = require("body-parser");
const nextI18next = require("../i18n");
const port = process.env.PORT || 3000;
const nextApp = next({ dev: process.env.NODE_ENV !== "production" });
const handle = nextApp.getRequestHandler();
nextApp.prepare().then(() => {
const server = express();
// parse application/json
server.use(bodyParser.json());
const sendMail = require("./sendMail");
server.use("/api/v1/communicate", sendMail);
server.use(nextI18NextMiddleware(nextI18next));
server.get("*", (req, res) => handle(req, res));
server.listen(port);
console.log(`> Ready on http://localhost:${port}`);
});
为了在 firebase 上托管应用程序,我在 src/functions/index.js 中使用了 firebase 函数:
const functions = require("firebase-functions");
const next = require("next");
var dev = process.env.NODE_ENV !== "production";
var app = next({ dev, conf: { distDir: "next" } });
var handle = app.getRequestHandler();
exports.next = functions.https.onRequest((req, res) => {
console.log("File: " + req.originalUrl); // log the page.js file that is being requested
return app.prepare().then(() => handle(req, res));
});
在项目的根目录中,我有 package.json:
{
"name": "src",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"install": "yarn build-all",
"next": "yarn build-firebase && cd \"src/app\" && yarn && yarn dev",
"preserve": "yarn build-all",
"serve": "firebase serve",
"predeploy": "yarn build-all",
"deploy": "firebase deploy",
"build-all": "yarn build-next && yarn build-firebase",
"build-next": "cd \"src/app\" && yarn && yarn build",
"build-firebase": "cd \"src/functions\" && yarn"
},
"engines": {
"node": "10"
}
}
当我运行命令时
yarn build-all
我有这个输出:
当我运行命令时
firebase deploy --only functions:next
我有这个输出:
目前,我的问题是我现在不知道如何在 firebase 托管上部署应用程序。不幸的是,我找不到任何可以帮助我理解问题的东西。我会很高兴听到至少一些假设,这可以帮助我理解问题。
先感谢您 !