Currently, I am working on a project that utilizes NextJS with Express for server-side routing.
lib/routes/getPages
const routes = require('next-routes')();
const getEntries = require('../helpers/getEntries');
module.exports = async (app) => {
const { items: [globalSetings] } = await getEntries({
content_type: 'xxxxxxxx',
include: 1,
limit: 1,
});
routes
.add('/', 'index')
.add(`/${globalSettings.fields.blogSlug}/:slug`, 'blog');
return routes.getRequestHandler(app);
};
server.js
const express = require('express');
const next = require('next');
const getPages = require('./lib/routes/getPages');
const app = next();
app.prepare().then(async () => {
const server = express();
const pageRoutes = await getPages(app);
server.use(pageRoutes);
server.listen(3000);
});
My concern arises when an admin changes a slug in the CMS while the app is running. It seems that I will have to restart the app for the new slug or route to take effect. Would implementing a webhook to listen for changes from the CMS and programmatically restart the app be the best solution, despite the potential overhead? Or, is there a more efficient way to handle this scenario?