pages/[...slug].js catches all of my sub folders but I need to exclude /public folder. How can I exclude the /public folder?
I have implemented this code and it works. But I wanted to exclude the /public folder somewhere above the page like next.config.js. Is this possible?
Page.getInitialProps = async (ctx) => {
if (ctx.asPath.indexOf("/public/") === 0) {
ctx.res.writeHead(404);
ctx.res.end();
} else {
// renders my page
}
}