我希望这个问题是清楚的,目前我的脑力已经到了极限。
我在生产中有一些Nginx重写,我需要在前端的nextjs应用程序中重现这个功能。
所以我的重写规则如下
const rewrites = process.env.NODE_ENV === "development" ?
[{
source: '/ovp/userdevices',
destination: 'https://userdevices.backendservices.dk'
},
{
source: '/ovp/userdevices/:path*',
destination: 'https://userdevices.backendservices.dk/:path*'
}
] : [];在我的配置中
async rewrites() {
console.log("Rewrites called");
return rewrites;
},我得到了控制台日志,阵列就是它应该是的样子。但是我的/ovp/userdevices urls永远不会重写,所以我们总是运行localhost:3000/ovp/userdevices。
我现在假设重写永远不会发生,因为这些应该在服务器端完成,也许所有的东西都是在前端呈现的,但我不知道如何测试这个假设。
我当前的配置如下所示
{
poweredByHeader: false,
target: 'serverless',
distDir: 'build',
basePath: '',
rewrites: [AsyncFunction: rewrites],
redirects: [AsyncFunction: redirects],
pageExtensions: [ 'route.js' ],
env: {
SUPPORTED_BROWSERS: 'chrome 84;chrome 83;edge 84;edge 83;firefox 79;firefox 78',
APP_VERSION: '0.0.1',
APP_NAME: 'some-app/app-self-service'
},
webpack: [Function: webpack]
}有谁能告诉我重写不会发生的原因吗?
关于编辑:我不会删除这个问题,因为也许有人会发现它的用途,但我错了,它被重写了它只是它的网址是失败的。我不知道为什么,因为我找到了一个更简单的方法来解决我的问题。
发布于 2021-01-12 01:49:50
您不能使用名称rewrites两次。让next.config.js看起来像这样:
module.exports = {
async rewrites() {
console.log("Rewrites called");
return process.env.NODE_ENV === "development"
? [
{
source: "/ovp/userdevices",
destination: "https://userdevices.backendservices.dk",
},
{
source: "/ovp/userdevices/:path*",
destination: "https://userdevices.backendservices.dk/:path*",
},
]
: [];
},
};https://stackoverflow.com/questions/65666389
复制相似问题