【发布时间】:2020-04-22 05:40:26
【问题描述】:
我正在尝试在根 url 上运行通过 Firebase 部署的 NextJS 应用,但它似乎只能在 /next 上运行,这给我的资产路径带来了一些问题,我只想让它在根上运行网址。如果我现在转到根 url,我会收到此错误:
如何让它在根 URL https://europe-west2-myfirstflutterapp-xxxxx.cloudfunctions.net/ 而不是 https://europe-west2-myfirstflutterapp-xxxxx.cloudfunctions.net/next 上运行?
我的firebase.json:
{
"hosting": {
"public": "./public",
"rewrites": [
{
"source": "**",
"function": "next"
}
]
},
"functions": {
"source": "functions"
}
}
我的functions/index.js:
'use strict';
const functions = require('firebase-functions');
const next = require('next');
const path = require('path');
const dev = process.env.NODE_ENV !== 'production';
// const app = next({dev, dir: path.join(__dirname, '../'), conf: {distDir: 'next'}});
const app = next({dev, conf: {distDir: 'next'}});
const handle = app.getRequestHandler();
exports.next = functions.region('europe-west2').https.onRequest(async (req, res) => {
console.log('File: ' + req.originalUrl); // log the page.js file that is being requested
await app.prepare();
handle(req, res);
});
【问题讨论】:
-
您能否编辑问题以更详细地显示您正在尝试的实际 URL 路径,以及该功能如何无法按照您期望的方式工作?
-
@DougStevenson 完成!
-
您已将默认的
.nextdist 目录更改为next。您正在运行构建版本的 nextjs (next build) 还是实时开发服务器?
标签: node.js firebase google-cloud-functions next.js