我想将 NextJS 应用程序与 Laravel 应用程序集成。
NextJS 应用程序负责路线
/
/node/123456789
/way/123456789
/relation/123456789
/install
其中 123456789 任何号码。
Laravel 应用程序应该负责所有其他 URL。
NextJS 应用程序的所有页面路由如下所示:
const [osmtype, osmid] = all;
const shortId =
osmtype && osmtype.match(/^node|way|relation$/)
? osmtype.substr(0, 1) + osmid
: id;
if (!shortId) {
return notFound();
}
我正在尝试通过重写 next.config.js 来做到这一点
目前我有这样的负前瞻正则表达式:
rewrites: () => {
return [
{
source: '/((?!node|way|relation|install):path*)',
destination: `http://pages.example.com/:path*`,
}
]
}
但是这不会匹配并调用 NextJS 应用程序的 404 页面。
我也尝试过
source: '/((?!node|way|relation|install)):path*',
这里我离得更近了一点。
调用类似
http://nextjsapp.example.com/bar
会导致在pages.example.com的Apache访问日志中出现
GET /r
- 所以不知何故:path*只捕获了最后一个字母。
如何使其匹配完整路径并将其传递到 Laravel 后端?
此外,我尝试了回退重写,但由于 NextJs 应用程序中路由的性质,这似乎不起作用 - 我仍然会收到 404 错误。
*
太多了 - 而且我不知道 destionation
中的反引号来自哪里。这有效:
source: '/((?!node|way|relation|install):path)',
destination: 'http://pages.example.com/:path',