A potential issue could be you having a POST route and a middleware for /usermsg, which could possibly clash. If the middleware is supposed to handle POST requests to /usermsg , it should be added after the POST route definition. Make sure that the middleware is actually sending something that can be used by app.use(). Here is the fixed code →
const express = require('express');
const app = express();
const cors = require('cors');
const port = 3000;
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.send('Root has been reached!');
console.log('Root has been reached');
});
app.post('/usermsg', (req, res) => {
const body = req.body;
console.log(body);
res.send('HTTP request from Postman received');
});
const middleware = require('./subscription');
// Use middleware after the route definition
app.use('/usermsg', middleware.router);
app.listen(port, () => {
console.log(`App listening at ${port}`);
});
Thanks for the prompt response. However, the issue doesn’t seem to be that. It works fine when I deploy the program and use the public url. However, doesn’t work with the webview url, which makes it super difficult to debug the code as the errors only occur in the ‘log’ after deploying the program