As I am in the process of creating an ecommerce platform for testing, one key aspect that I want to address is ensuring that any page not found in my database automatically directs users to an error page. This way, even if they encounter a dead end, they can still explore other areas of the site and engage in different activities.
In the backend of my system, I have an error file that controls this functionality. However, I'm looking for guidance on how to modify it to achieve the desired outcome using vanilla JavaScript.
const express = require('express');
const app = express();
app.post('/submit-form', (req, res) => {
if (!isValid(req.body)) {
res.redirect('/error');
} else {
res.send('Form submitted successfully!');
}
});
app.get('/error', (req, res) => {
res.sendFile(__dirname + '/public/error.html');`your text`
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});