Can anyone help me resolve this issue in React Next.js? It was working fine when I ran the same code on my local server. Additionally, when I run 'npm run build' on the server, it works fine too. However, when I try to set up the app with PM2, it returns a 'cannot GET /' error. I'm new to this, so I would really appreciate it if someone could help me resolve the issue.
const { createServer } = require('http');
const { parse } = require('url');
const next = require('next');
const express = require('express');
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
const dev = process.env.NODE_ENV !== 'production';
const hostname = 'localhost';
const port = 3000;
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.use(bodyParser.urlencoded({ extended: false }));
server.use(bodyParser.json());
server.listen(port, () => {
console.log(`> Ready on http://${hostname}:${port}`);
});
});
.htaccess
<IfModule mod_rewrite.c>
DirectoryIndex disabled
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)?$ http://127.0.0.1:3000/$1 [P,L]
</IfModule>