是否可以将NextJs应用程序作为子目录添加到防火墙主机上的ReactJs应用程序中?我有一个主应用程序已经部署到firebase与一个域,我想添加一个NextJs应用到它的子目录"/blogs“,以SEO为目的。这个是可能的吗?如果是,怎么做?我试过重写,但没有取得任何成功。
Update I通过以下操作成功地使其工作了一点:
目录:
.
+-- _projectFolder
| +-- firebase.json
| +-- .firebaserc
+-- Reactjs Files...
+-- nextApp
| +-- server.js
| +-- Nextjs files...firebase.json:
"hosting": [
{
"target": "blog",
"public": "./nextApp/public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"function": "nextServer"
}
]
},
{
"target": "main",
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "/blogs/**",
"function": "nextServer"
},
{
"source": "/blogs",
"function": "nextServer"
}
]
}
],
"functions": {
"source": "./nextApp",
"runtime": "nodejs16"
}
}server.js的代码
const { https } = require("firebase-functions")
const { default: next } = require("next")
const isDev = process.env.NODE_ENV !== "production"
const nextjsDistDir = require("./next.config.js").distDir
const server = next({
dev: false,
//location of .next generated after running -> yarn build
conf: { distDir: nextjsDistDir },
})
const nextjsHandle = server.getRequestHandler()
exports.nextServer = https.onRequest((req, res) => {
return server.prepare().then(() => {
return nextjsHandle(req, res)
})
})
/*
firebase-admin,firebase-functions
require these plugins, install them
*/next.config.js有一个basePath of basePath:"/blogs“
现在唯一的问题是,当构建在防火墙上时,不知何故没有检测到next.config.js。没有一个图像域或basePath在那里工作,这些在本地工作很好,我需要在server.js文件中进行任何更改吗?
发布于 2022-09-17 00:20:48
实际上,配置似乎很好。您只能为接收所有请求添加一个/**。
{
"hosting": {
"target": "main",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/blogs/**",
"destination": "/nextApp/index.html"
}
]
}如果这是一个nextjs应用程序,我建议检查您是否正确地设置了基本路径-> 文档。
https://stackoverflow.com/questions/73751138
复制相似问题