Closed jesstelford closed 1 year ago
We just manage to build it for Now 2.0 as a POC. Sharing the solution here and if no one beats us to it we will try to do a PR with a better solution asap.
const fs = require("fs");
const nextRoutes = require("../routes");
const nowConfig = require("../now.json");
if(!nowConfig.routes) {
nowConfig.routes = []
}
nextRoutes.routes.forEach((route) => {
if (nowConfig.routes.filter(e => e.src === route.regex.source).length === 0) {
nowConfig.routes.push({
src: route.regex.source,
dest: route.page
})
}
})
fs.writeFile('now.json', JSON.stringify(nowConfig, false, 2), (err) => {
if (err) {
console.error(err);
return;
};
console.log("now.json has been updated");
});
The idea is simply to fetch routing and update now.json
with it. That would keep it backwards compatible with link generation using named routes in this package.
We wrote a simple CLI tool for this based on the above POC. https://www.npmjs.com/package/next-routes-now
I created my own routes middleware to use Now 2.0 json routing format here
Now 2.0 has been released: https://zeit.co/blog/now-2
Specifically, the next.js docs encourage not using a file that specifies all the routes:
The alternative proposed is to use a
now.json#routes
config: https://zeit.co/docs/v2/deployments/configuration#routesHowever, this loses the ability to do reverse-route lookups which I love from
next-routes
.Is there a way to interop the two concepts and reap benefits of both?